Skip to content

Commit d83a0d7

Browse files
committed
Allow 'verbatimModuleSyntax' with transpileModule
1 parent e1488fe commit d83a0d7

File tree

280 files changed

+1436
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+1436
-74
lines changed

src/services/transpile.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export interface TranspileOutput {
4343
sourceMapText?: string;
4444
}
4545

46+
const optionsRedundantWithVerbatimModuleSyntax = new Set([
47+
"isolatedModules",
48+
"preserveValueImports",
49+
"importsNotUsedAsValues"
50+
]);
51+
4652
/*
4753
* This function will compile source text from 'input' argument using specified compiler options.
4854
* If not options are provided - it will use a set of default compiler options.
@@ -66,7 +72,10 @@ export function transpileModule(input: string, transpileOptions: TranspileOption
6672
}
6773

6874
for (const option of transpileOptionValueCompilerOptions) {
69-
options[option.name] = option.transpileOptionValue;
75+
// Do not set redundant config options if `verbatimModuleSyntax` was supplied.
76+
if (!options.verbatimModuleSyntax || !optionsRedundantWithVerbatimModuleSyntax.has(option.name)) {
77+
options[option.name] = option.transpileOptionValue;
78+
}
7079
}
7180

7281
// transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.

src/testRunner/unittests/services/transpile.ts

Lines changed: 178 additions & 73 deletions
Large diffs are not rendered by default.

tests/baselines/reference/transpile/Correctly serialize metadata when transpile with CommonJS option (verbatimModuleSyntax=true).js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Correctly serialize metadata when transpile with CommonJS option (verbatimModuleSyntax=true).oldTranspile.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
2+
3+
4+
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
5+
==== file.ts (0 errors) ====
6+
import IFoo = Namespace.IFoo;export type { IFoo };

tests/baselines/reference/transpile/Does not elide import equals referenced only by export type (verbatimModuleSyntax=true).js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
2+
3+
4+
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
5+
==== file.ts (0 errors) ====
6+
import IFoo = Namespace.IFoo;export type { IFoo };

tests/baselines/reference/transpile/Does not elide import equals referenced only by export type (verbatimModuleSyntax=true).oldTranspile.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
2+
3+
4+
!!! error TS5107: Option 'target=ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error.
5+
==== file.ts (0 errors) ====
6+
import IFoo = Namespace.IFoo;export { type IFoo };

tests/baselines/reference/transpile/Does not elide import equals referenced only by type only export specifier (verbatimModuleSyntax=true).js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)