mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 13:45:34 -05:00
Fix import assertion occurrences crash and make import assertion parsing more generous (#47535)
This commit is contained in:
@@ -39786,6 +39786,16 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!isImportEqualsDeclaration(node) && node.assertClause) {
|
||||
let hasError = false;
|
||||
for (const clause of node.assertClause.elements) {
|
||||
if (!isStringLiteral(clause.value)) {
|
||||
hasError = true;
|
||||
error(clause.value, Diagnostics.Import_assertion_values_must_be_string_literal_expressions);
|
||||
}
|
||||
}
|
||||
return !hasError;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3369,6 +3369,10 @@
|
||||
"category": "Error",
|
||||
"code": 2836
|
||||
},
|
||||
"Import assertion values must be string literal expressions.": {
|
||||
"category": "Error",
|
||||
"code": 2837
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@@ -4024,7 +4024,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// @api
|
||||
function createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry {
|
||||
function createAssertEntry(name: AssertionKey, value: Expression): AssertEntry {
|
||||
const node = createBaseNode<AssertEntry>(SyntaxKind.AssertEntry);
|
||||
node.name = name;
|
||||
node.value = value;
|
||||
@@ -4033,7 +4033,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// @api
|
||||
function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry {
|
||||
function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry {
|
||||
return node.name !== name
|
||||
|| node.value !== value
|
||||
? update(createAssertEntry(name, value), node)
|
||||
|
||||
@@ -7281,7 +7281,7 @@ namespace ts {
|
||||
const pos = getNodePos();
|
||||
const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
const value = parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
|
||||
const value = parseAssignmentExpressionOrHigher();
|
||||
return finishNode(factory.createAssertEntry(name, value), pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -3055,7 +3055,7 @@ namespace ts {
|
||||
readonly kind: SyntaxKind.AssertEntry;
|
||||
readonly parent: AssertClause;
|
||||
readonly name: AssertionKey;
|
||||
readonly value: StringLiteral;
|
||||
readonly value: Expression;
|
||||
}
|
||||
|
||||
export interface AssertClause extends Node {
|
||||
@@ -7446,8 +7446,8 @@ namespace ts {
|
||||
updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
|
||||
createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
|
||||
updateAssertClause(node: AssertClause, elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
|
||||
createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry;
|
||||
updateAssertEntry (node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry;
|
||||
createAssertEntry(name: AssertionKey, value: Expression): AssertEntry;
|
||||
updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry;
|
||||
createNamespaceImport(name: Identifier): NamespaceImport;
|
||||
updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport;
|
||||
createNamespaceExport(name: Identifier): NamespaceExport;
|
||||
|
||||
@@ -1090,7 +1090,7 @@ namespace ts {
|
||||
Debug.type<AssertEntry>(node);
|
||||
return factory.updateAssertEntry(node,
|
||||
nodeVisitor(node.name, visitor, isAssertionKey),
|
||||
nodeVisitor(node.value, visitor, isStringLiteral));
|
||||
nodeVisitor(node.value, visitor, isExpressionNode));
|
||||
|
||||
case SyntaxKind.ImportClause:
|
||||
Debug.type<ImportClause>(node);
|
||||
|
||||
Reference in New Issue
Block a user