Skip to content

Commit 6ea3c55

Browse files
committed
Fix cr issues
1 parent 7df4964 commit 6ea3c55

File tree

6 files changed

+22
-60
lines changed

6 files changed

+22
-60
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39000,11 +39000,11 @@ namespace ts {
3900039000
function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) {
3900139001
if (declaration.assertClause) {
3900239002
if (moduleKind !== ModuleKind.ESNext) {
39003-
error(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext);
39003+
return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext);
3900439004
}
3900539005

3900639006
if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) {
39007-
error(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
39007+
return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
3900839008
}
3900939009
}
3901039010
}
@@ -43162,7 +43162,16 @@ namespace ts {
4316243162
return false;
4316343163
}
4316443164

43165-
function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray<Expression>): boolean {
43165+
function checkGrammarImportCallExpression(node: ImportCall): boolean {
43166+
if (moduleKind === ModuleKind.ES2015) {
43167+
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd);
43168+
}
43169+
43170+
if (node.typeArguments) {
43171+
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments);
43172+
}
43173+
43174+
const nodeArguments = node.arguments;
4316643175
if (moduleKind !== ModuleKind.ESNext) {
4316743176
// We are allowed trailing comma after proposal-import-assertions.
4316843177
checkGrammarForDisallowedTrailingComma(nodeArguments);
@@ -43172,25 +43181,11 @@ namespace ts {
4317243181
return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_import_only_supports_a_second_argument_when_the_module_option_is_set_to_esnext);
4317343182
}
4317443183
}
43175-
if (nodeArguments.length !== 1) {
43176-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments);
43177-
}
43178-
return false;
43179-
}
43180-
43181-
function checkGrammarImportCallExpression(node: ImportCall): boolean {
43182-
if (moduleKind === ModuleKind.ES2015) {
43183-
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd);
43184-
}
4318543184

43186-
if (node.typeArguments) {
43187-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments);
43185+
if (nodeArguments.length === 0 || nodeArguments.length > 2) {
43186+
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments);
4318843187
}
4318943188

43190-
const nodeArguments = node.arguments;
43191-
if (checkGrammarImportCallArguments(node, nodeArguments)) {
43192-
return true;
43193-
}
4319443189
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
4319543190
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
4319643191
if (nodeArguments.length && isSpreadElement(nodeArguments[0])) {

src/compiler/emitter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,8 +3327,7 @@ namespace ts {
33273327
}
33283328
emitExpression(node.moduleSpecifier);
33293329
if (node.assertClause) {
3330-
writeSpace();
3331-
emit(node.assertClause);
3330+
emitWithLeadingSpace(node.assertClause);
33323331
}
33333332
writeTrailingSemicolon();
33343333
}
@@ -3399,8 +3398,7 @@ namespace ts {
33993398
emitExpression(node.moduleSpecifier);
34003399
}
34013400
if (node.assertClause) {
3402-
writeSpace();
3403-
emit(node.assertClause);
3401+
emitWithLeadingSpace(node.assertClause);
34043402
}
34053403
writeTrailingSemicolon();
34063404
}

src/compiler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7341,8 +7341,8 @@ namespace ts {
73417341
updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration;
73427342
createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
73437343
updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
7344-
createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration;
7345-
updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration;
7344+
createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration;
7345+
updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration;
73467346
createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
73477347
updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
73487348
createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
@@ -7360,7 +7360,7 @@ namespace ts {
73607360
createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
73617361
updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment;
73627362
createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration;
7363-
updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration;
7363+
updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause?: AssertClause): ExportDeclaration;
73647364
createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
73657365
updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
73667366
createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;

src/compiler/utilitiesPublic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,6 @@ namespace ts {
13781378
/* @internal */
13791379
export function isAssignmentPattern(node: Node): node is AssignmentPattern {
13801380
const kind = node.kind;
1381-
13821381
return kind === SyntaxKind.ArrayLiteralExpression
13831382
|| kind === SyntaxKind.ObjectLiteralExpression;
13841383
}
Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
tests/cases/conformance/importAssertion/3.ts(2,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
2-
tests/cases/conformance/importAssertion/3.ts(3,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
3-
tests/cases/conformance/importAssertion/3.ts(4,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
4-
tests/cases/conformance/importAssertion/3.ts(5,12): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
5-
tests/cases/conformance/importAssertion/3.ts(7,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
61
tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
72
tests/cases/conformance/importAssertion/3.ts(9,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
8-
tests/cases/conformance/importAssertion/3.ts(10,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
93

104

115
==== tests/cases/conformance/importAssertion/0.ts (0 errors) ====
@@ -29,32 +23,20 @@ tests/cases/conformance/importAssertion/3.ts(10,11): message TS1450: Dynamic imp
2923
c;
3024
d;
3125

32-
==== tests/cases/conformance/importAssertion/3.ts (8 errors) ====
26+
==== tests/cases/conformance/importAssertion/3.ts (2 errors) ====
3327
const a = import('./0')
3428
const b = import('./0', { assert: { type: "json" } })
35-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
3729
const c = import('./0', { assert: { type: "json", ttype: "typo" } })
38-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
4030
const d = import('./0', { assert: {} })
41-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
4331
const dd = import('./0', {})
44-
~~~~~~~~~~~~~~~~~
45-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
4632
declare function foo(): any;
4733
const e = import('./0', foo())
48-
~~~~~~~~~~~~~~~~~~~~
49-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
5034
const f = import()
5135
~~~~~~~~
5236
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
5337
const g = import('./0', {}, {})
5438
~~~~~~~~~~~~~~~~~~~~~
5539
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
5640
const h = import('./0', { assert: { type: "json" }},)
57-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58-
!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments
5941

6042

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
tests/cases/conformance/importAssertion/1.ts(1,27): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
2-
tests/cases/conformance/importAssertion/1.ts(1,27): error TS2821: Import assertions cannot be used with type-only imports or exports.
32
tests/cases/conformance/importAssertion/1.ts(2,30): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
4-
tests/cases/conformance/importAssertion/1.ts(2,30): error TS2821: Import assertions cannot be used with type-only imports or exports.
53
tests/cases/conformance/importAssertion/2.ts(1,31): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
6-
tests/cases/conformance/importAssertion/2.ts(1,31): error TS2821: Import assertions cannot be used with type-only imports or exports.
74
tests/cases/conformance/importAssertion/2.ts(2,33): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
8-
tests/cases/conformance/importAssertion/2.ts(2,33): error TS2821: Import assertions cannot be used with type-only imports or exports.
95

106

117
==== tests/cases/conformance/importAssertion/0.ts (0 errors) ====
128
export interface I { }
139

14-
==== tests/cases/conformance/importAssertion/1.ts (4 errors) ====
10+
==== tests/cases/conformance/importAssertion/1.ts (2 errors) ====
1511
export type {} from './0' assert { type: "json" }
1612
~~~~~~~~~~~~~~~~~~~~~~~
1713
!!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
18-
~~~~~~~~~~~~~~~~~~~~~~~
19-
!!! error TS2821: Import assertions cannot be used with type-only imports or exports.
2014
export type { I } from './0' assert { type: "json" }
2115
~~~~~~~~~~~~~~~~~~~~~~~
2216
!!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
23-
~~~~~~~~~~~~~~~~~~~~~~~
24-
!!! error TS2821: Import assertions cannot be used with type-only imports or exports.
2517

26-
==== tests/cases/conformance/importAssertion/2.ts (4 errors) ====
18+
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
2719
import type { I } from './0' assert { type: "json" }
2820
~~~~~~~~~~~~~~~~~~~~~~~
2921
!!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
30-
~~~~~~~~~~~~~~~~~~~~~~~
31-
!!! error TS2821: Import assertions cannot be used with type-only imports or exports.
3222
import type * as foo from './0' assert { type: "json" }
3323
~~~~~~~~~~~~~~~~~~~~~~~
3424
!!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'.
35-
~~~~~~~~~~~~~~~~~~~~~~~
36-
!!! error TS2821: Import assertions cannot be used with type-only imports or exports.
3725

3826

0 commit comments

Comments
 (0)