test: compiler for bundle
ADD
internal/compiler/transforms/compileForBundle/index.test.ts
+import {
+ createFixtureTests,
+ createMockWorker,
+ findFixtureInput,
+} from "@internal/test-helpers";
+import {printDiagnosticsToString} from "@internal/cli-diagnostics";
+import {createDefaultProjectConfig} from "@internal/project";
+import {resolveBrowsers} from "@internal/codec-browsers";
+import {UIDPathMap, createUIDPath} from "@internal/path";
+
+const promise = createFixtureTests(async (fixture, t) => {
+ const {worker, performFileOperation, addProject} = createMockWorker();
+ const {input, handler} = findFixtureInput(fixture, undefined);
+
+ const filename = input.relative;
+ const content = input.contentAsText();
+
+ const res = await performFileOperation(
+ {
+ uid: filename.join(),
+ sourceText: content,
+ project: addProject({
+ ...createDefaultProjectConfig(),
+ targets: new Map([
+ [
+ "default",
+ resolveBrowsers(">0%").map((browser) => ({
+ name: browser.getId(),
+ version: browser.getVersion(),
+ })),
+ ],
+ ]),
+ }),
+ },
+ async (ref) => {
+ return await worker.api.compile(
+ ref,
+ "compileForBundle",
+ {
+ target: "default",
+ bundle: {
+ assetPath: input.relative,
+ __filename: input.relative,
+ moduleAll: true,
+ moduleId: createUIDPath(input.relative.join()),
+ relativeSourcesToModuleId: new Map(),
+ resolvedImports: new UIDPathMap(),
+ },
+ },
+ {
+ sourceTypeJS: "module",
+ },
+ );
+ },
+ );
+ if (res === undefined) {
+ throw new Error("No format value returned");
+ }
+
+ const snapshotFile = input.absolute.getParent().append(
+ input.absolute.getExtensionlessBasename(),
+ ).join();
+
+ const snapshot = t.customSnapshot(snapshotFile, {language: handler.language});
+
+ snapshot.named("Input", content);
+
+ snapshot.named("Output", res.value.compiledCode);
+
+ snapshot.named(
+ "Diagnostics",
+ await printDiagnosticsToString({
+ diagnostics: res.value.diagnostics,
+ suppressions: res.value.suppressions,
+ }),
+ );
+});
+
+// @ts-expect-error allow top level await
+await promise;

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/asyncImportTransform/input.test.md
+# `index.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/transforms/compileForBundle/index.test.ts --update-snapshots` to update.
+
+## `asyncImportTransform`
+
+### `Diagnostics`
+
+```ts
+
+```
+
+### `Input`
+
+```ts
+import foo = require('module')
+
+```
+
+### `Output`
+
+```ts
+ const ___R$asyncImportTransform$input_ts = {};
+ const ___R$$priv$asyncImportTransform$input_ts$foo = require("module");
+
+```

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/asyncImportTransform/input.ts
+import foo = require('module')

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/__dirname/input.test.md
+# `index.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/transforms/compileForBundle/index.test.ts --update-snapshots` to update.
+
+## `metaPropertyTransform > __dirname`
+
+### `Diagnostics`
+
+```ts
+
+```
+
+### `Input`
+
+```ts
+const t = __dirname;
+
+```
+
+### `Output`
+
+```ts
+ const ___R$metaPropertyTransform$__dirname$input_ts = {};
+ const ___R$$priv$metaPropertyTransform$__dirname$input_ts$t =
+ __dirname + "/" + "metaPropertyTransform/__dirname/";
+
+```

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/__dirname/input.ts
+const t = __dirname;

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/__filename/input.test.md
+# `index.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/transforms/compileForBundle/index.test.ts --update-snapshots` to update.
+
+## `metaPropertyTransform > __filename`
+
+### `Diagnostics`
+
+```ts
+
+```
+
+### `Input`
+
+```ts
+const t = __filename;
+
+```
+
+### `Output`
+
+```ts
+ const ___R$metaPropertyTransform$__filename$input_ts = {};
+ const ___R$$priv$metaPropertyTransform$__filename$input_ts$t =
+ __dirname + "/" + "metaPropertyTransform/__filename/input.ts";
+
+```

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/__filename/input.ts
+const t = __filename;

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/import.meta.url/input.test.md
+# `index.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/transforms/compileForBundle/index.test.ts --update-snapshots` to update.
+
+## `metaPropertyTransform > import.meta.url`
+
+### `Diagnostics`
+
+```ts
+
+```
+
+### `Input`
+
+```ts
+const t = import.meta.url;
+
+```
+
+### `Output`
+
+```ts
+ const ___R$metaPropertyTransform$import_meta_url$input_ts = {};
+ const ___R$$priv$metaPropertyTransform$import_meta_url$input_ts$t =
+ "file://" +
+ (__dirname + "/" + "metaPropertyTransform/import.meta.url/input.ts");
+
+```

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/metaPropertyTransform/import.meta.url/input.ts
+const t = import.meta.url;

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/requireRewriteTransform/input.test.md
+# `index.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/transforms/compileForBundle/index.test.ts --update-snapshots` to update.
+
+## `requireRewriteTransform`
+
+### `Diagnostics`
+
+```ts
+
+```
+
+### `Input`
+
+```ts
+const a = {};
+const b = 3;
+
+module.exports = a;
+module.exports = b;
+
+```
+
+### `Output`
+
+```ts
+ const ___R$requireRewriteTransform$input_ts = {};
+ const ___R$$priv$requireRewriteTransform$input_ts$a = {};
+ const ___R$$priv$requireRewriteTransform$input_ts$b = 3;
+
+ ___R$requireRewriteTransform$input_ts = ___R$$priv$requireRewriteTransform$input_ts$a;
+ ___R$requireRewriteTransform$input_ts = ___R$$priv$requireRewriteTransform$input_ts$b;
+
+```

ADD
internal/compiler/transforms/compileForBundle/test-fixtures/requireRewriteTransform/input.ts
+const a = {};
+const b = 3;
+
+module.exports = a;
+module.exports = b;

test: compiler for bundle (#1628)