Skip to content

Commit fd1806e

Browse files
committed
refactor: rename transformStaticImports
1 parent baaacc6 commit fd1806e

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

packages/instrument-bundler/src/__tests__/transform.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { transformStaticImports } from '../transform.js';
3+
import { transformImports } from '../transform.js';
44

5-
describe('transformStaticImports', () => {
5+
describe('transformImports', () => {
66
it('should transform a default import', () => {
7-
expect(transformStaticImports("import React from 'react';")).toBe(
8-
"const { default: React } = await import('react');"
9-
);
7+
expect(transformImports("import React from 'react';")).toBe("const { default: React } = await import('react');");
108
});
119
it('should transform named imports', () => {
12-
expect(transformStaticImports("import { useEffect, useState } from 'react';")).toBe(
10+
expect(transformImports("import { useEffect, useState } from 'react';")).toBe(
1311
"const { useEffect, useState } = await import('react');"
1412
);
1513
});
1614
it('should transform named and default imports from the same source', () => {
17-
expect(transformStaticImports("import React, { useState } from 'react';")).toBe(
15+
expect(transformImports("import React, { useState } from 'react';")).toBe(
1816
"const { useState, default: React } = await import('react');"
1917
);
2018
});
2119
it('should transform a namespace import', () => {
22-
expect(transformStaticImports("import * as React from 'react';")).toBe("const React = await import('react');");
20+
expect(transformImports("import * as React from 'react';")).toBe("const React = await import('react');");
2321
});
2422
it('should transform named and default imports from the same source', () => {
25-
expect(transformStaticImports("import _ from 'lodash'; import { useEffect, useState } from 'react';")).toBe(
23+
expect(transformImports("import _ from 'lodash'; import { useEffect, useState } from 'react';")).toBe(
2624
"const { default: _ } = await import('lodash'); const { useEffect, useState } = await import('react');"
2725
);
2826
});

packages/instrument-bundler/src/bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { build } from './build.js';
22
import { preprocess } from './preprocess.js';
3-
import { transformStaticImports } from './transform.js';
3+
import { transformImports } from './transform.js';
44
import * as esbuild from './vendor/esbuild.js';
55

66
import type { BundleOptions } from './schemas.js';
@@ -60,6 +60,6 @@ export async function createBundle(output: BuildOutput, options: { minify: boole
6060
export async function bundle({ inputs, minify = true }: BundleOptions): Promise<string> {
6161
preprocess(inputs);
6262
const result = await build({ inputs });
63-
result.js = transformStaticImports(result.js);
63+
result.js = transformImports(result.js);
6464
return createBundle(result, { minify });
6565
}

packages/instrument-bundler/src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function transformImportClause(importClause: ImportClause) {
1818
return `{ ${names.join(', ')} }`;
1919
}
2020

21-
export function transformStaticImports(code: string) {
21+
export function transformImports(code: string) {
2222
let indexDiff = 0;
2323
for (const {
2424
endIndex: _endIndex,

0 commit comments

Comments
 (0)