diff --git a/packages/typescript/src/api/node/encoder.generated.ts b/packages/typescript/src/api/node/encoder.generated.ts index df5572d9690aa..7b9c4de1425f6 100644 --- a/packages/typescript/src/api/node/encoder.generated.ts +++ b/packages/typescript/src/api/node/encoder.generated.ts @@ -91,7 +91,7 @@ export function getNodeCommonData(node: Node): number { case SyntaxKind.ImportType: return ((node as ImportTypeNode).isTypeOf ? 1 : 0) << 24; case SyntaxKind.ImportClause: - return ((node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword ? 1 : (node as ImportClause).phaseModifier === SyntaxKind.DeferKeyword ? 2 : 0) << 24; + return ((node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword ? 1 : (node as ImportClause).phaseModifier === SyntaxKind.DeferKeyword ? 2 : (node as ImportClause).phaseModifier === SyntaxKind.SourceKeyword ? 3 : 0) << 24; case SyntaxKind.ImportSpecifier: return ((node as ImportSpecifier).isTypeOnly ? 1 : 0) << 24; case SyntaxKind.JSDocTypeLiteral: diff --git a/packages/typescript/src/api/node/node.generated.ts b/packages/typescript/src/api/node/node.generated.ts index d9a8092261627..d1e00242f1407 100644 --- a/packages/typescript/src/api/node/node.generated.ts +++ b/packages/typescript/src/api/node/node.generated.ts @@ -529,7 +529,7 @@ export class RemoteNode extends RemoteNodeBase implements Node { case SyntaxKind.ImportClause: { const idx = (this.data >> 24) & 0x3; if (idx === 0) return undefined; - return idx === 1 ? SyntaxKind.TypeKeyword : idx === 2 ? SyntaxKind.DeferKeyword : undefined; + return idx === 1 ? SyntaxKind.TypeKeyword : idx === 2 ? SyntaxKind.DeferKeyword : idx === 3 ? SyntaxKind.SourceKeyword : undefined; } } } diff --git a/packages/typescript/src/ast/ast.generated.ts b/packages/typescript/src/ast/ast.generated.ts index 76ddfe362ae96..2c11e911877ed 100644 --- a/packages/typescript/src/ast/ast.generated.ts +++ b/packages/typescript/src/ast/ast.generated.ts @@ -159,7 +159,8 @@ export type KeywordSyntaxKind = | SyntaxKind.BigIntKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.OfKeyword - | SyntaxKind.DeferKeyword; + | SyntaxKind.DeferKeyword + | SyntaxKind.SourceKeyword; export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type KeywordExpressionSyntaxKind = SyntaxKind.NullKeyword | SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword | SyntaxKind.ThisKeyword | SyntaxKind.SuperKeyword | SyntaxKind.ImportKeyword; @@ -330,7 +331,8 @@ export type TokenSyntaxKind = | SyntaxKind.BigIntKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.OfKeyword - | SyntaxKind.DeferKeyword; + | SyntaxKind.DeferKeyword + | SyntaxKind.SourceKeyword; export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFile | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; export type JSDocNodeSyntaxKind = | SyntaxKind.JSDocTypeExpression @@ -369,7 +371,7 @@ export type JSDocNodeSyntaxKind = | SyntaxKind.JSDocThrowsTag | SyntaxKind.JSDocSatisfiesTag | SyntaxKind.JSDocImportTag; -export type ImportPhaseModifierSyntaxKind = SyntaxKind.TypeKeyword | SyntaxKind.DeferKeyword; +export type ImportPhaseModifierSyntaxKind = SyntaxKind.TypeKeyword | SyntaxKind.DeferKeyword | SyntaxKind.SourceKeyword; export type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; export type PrefixUnaryOperator = SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; export type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; diff --git a/packages/typescript/src/ast/is.generated.ts b/packages/typescript/src/ast/is.generated.ts index 2654438f83ab3..953fbafd17b6f 100644 --- a/packages/typescript/src/ast/is.generated.ts +++ b/packages/typescript/src/ast/is.generated.ts @@ -2773,7 +2773,8 @@ export function isJsxTokenKind(kind: SyntaxKind): kind is JsxTokenSyntaxKind { export function isImportPhaseModifierKind(kind: SyntaxKind): kind is ImportPhaseModifierSyntaxKind { return kind === SyntaxKind.TypeKeyword - || kind === SyntaxKind.DeferKeyword; + || kind === SyntaxKind.DeferKeyword + || kind === SyntaxKind.SourceKeyword; } export function isPostfixUnaryOperator(kind: SyntaxKind): kind is PostfixUnaryOperator { diff --git a/packages/typescript/src/ast/scanner.ts b/packages/typescript/src/ast/scanner.ts index 8e956bb967f54..253aa2d064c65 100644 --- a/packages/typescript/src/ast/scanner.ts +++ b/packages/typescript/src/ast/scanner.ts @@ -149,6 +149,7 @@ export const textToKeywordObj: Record = { return: SyntaxKind.ReturnKeyword, satisfies: SyntaxKind.SatisfiesKeyword, set: SyntaxKind.SetKeyword, + source: SyntaxKind.SourceKeyword, static: SyntaxKind.StaticKeyword, string: SyntaxKind.StringKeyword, super: SyntaxKind.SuperKeyword, diff --git a/packages/typescript/src/enums/syntaxKind.enum.ts b/packages/typescript/src/enums/syntaxKind.enum.ts index 400c16806abf5..dbe8c6124d109 100644 --- a/packages/typescript/src/enums/syntaxKind.enum.ts +++ b/packages/typescript/src/enums/syntaxKind.enum.ts @@ -168,191 +168,192 @@ export enum SyntaxKind { OverrideKeyword = 164, OfKeyword = 165, DeferKeyword = 166, - QualifiedName = 167, - ComputedPropertyName = 168, - TypeParameter = 169, - Parameter = 170, - Decorator = 171, - PropertySignature = 172, - PropertyDeclaration = 173, - MethodSignature = 174, - MethodDeclaration = 175, - ClassStaticBlockDeclaration = 176, - Constructor = 177, - GetAccessor = 178, - SetAccessor = 179, - CallSignature = 180, - ConstructSignature = 181, - IndexSignature = 182, - TypePredicate = 183, - TypeReference = 184, - FunctionType = 185, - ConstructorType = 186, - TypeQuery = 187, - TypeLiteral = 188, - ArrayType = 189, - TupleType = 190, - OptionalType = 191, - RestType = 192, - UnionType = 193, - IntersectionType = 194, - ConditionalType = 195, - InferType = 196, - ParenthesizedType = 197, - ThisType = 198, - TypeOperator = 199, - IndexedAccessType = 200, - MappedType = 201, - LiteralType = 202, - NamedTupleMember = 203, - TemplateLiteralType = 204, - TemplateLiteralTypeSpan = 205, - ImportType = 206, - ObjectBindingPattern = 207, - ArrayBindingPattern = 208, - BindingElement = 209, - ArrayLiteralExpression = 210, - ObjectLiteralExpression = 211, - PropertyAccessExpression = 212, - ElementAccessExpression = 213, - CallExpression = 214, - NewExpression = 215, - TaggedTemplateExpression = 216, - TypeAssertionExpression = 217, - ParenthesizedExpression = 218, - FunctionExpression = 219, - ArrowFunction = 220, - DeleteExpression = 221, - TypeOfExpression = 222, - VoidExpression = 223, - AwaitExpression = 224, - PrefixUnaryExpression = 225, - PostfixUnaryExpression = 226, - BinaryExpression = 227, - ConditionalExpression = 228, - TemplateExpression = 229, - YieldExpression = 230, - SpreadElement = 231, - ClassExpression = 232, - OmittedExpression = 233, - ExpressionWithTypeArguments = 234, - AsExpression = 235, - NonNullExpression = 236, - MetaProperty = 237, - SyntheticExpression = 238, - SatisfiesExpression = 239, - TemplateSpan = 240, - SemicolonClassElement = 241, - Block = 242, - EmptyStatement = 243, - VariableStatement = 244, - ExpressionStatement = 245, - IfStatement = 246, - DoStatement = 247, - WhileStatement = 248, - ForStatement = 249, - ForInStatement = 250, - ForOfStatement = 251, - ContinueStatement = 252, - BreakStatement = 253, - ReturnStatement = 254, - WithStatement = 255, - SwitchStatement = 256, - LabeledStatement = 257, - ThrowStatement = 258, - TryStatement = 259, - DebuggerStatement = 260, - VariableDeclaration = 261, - VariableDeclarationList = 262, - FunctionDeclaration = 263, - ClassDeclaration = 264, - InterfaceDeclaration = 265, - TypeAliasDeclaration = 266, - EnumDeclaration = 267, - ModuleDeclaration = 268, - ModuleBlock = 269, - CaseBlock = 270, - NamespaceExportDeclaration = 271, - ImportEqualsDeclaration = 272, - ImportDeclaration = 273, - ImportClause = 274, - NamespaceImport = 275, - NamedImports = 276, - ImportSpecifier = 277, - ExportAssignment = 278, - ExportDeclaration = 279, - NamedExports = 280, - NamespaceExport = 281, - ExportSpecifier = 282, - MissingDeclaration = 283, - ExternalModuleReference = 284, - JsxElement = 285, - JsxSelfClosingElement = 286, - JsxOpeningElement = 287, - JsxClosingElement = 288, - JsxFragment = 289, - JsxOpeningFragment = 290, - JsxClosingFragment = 291, - JsxAttribute = 292, - JsxAttributes = 293, - JsxSpreadAttribute = 294, - JsxExpression = 295, - JsxNamespacedName = 296, - CaseClause = 297, - DefaultClause = 298, - HeritageClause = 299, - CatchClause = 300, - ImportAttributes = 301, - ImportAttribute = 302, - PropertyAssignment = 303, - ShorthandPropertyAssignment = 304, - SpreadAssignment = 305, - EnumMember = 306, - SourceFile = 307, - JSDocTypeExpression = 308, - JSDocNameReference = 309, - JSDocAllType = 310, - JSDocNullableType = 311, - JSDocNonNullableType = 312, - JSDocOptionalType = 313, - JSDocVariadicType = 314, - JSDoc = 315, - JSDocText = 316, - JSDocTypeLiteral = 317, - JSDocSignature = 318, - JSDocLink = 319, - JSDocLinkCode = 320, - JSDocLinkPlain = 321, - JSDocUnknownTag = 322, - JSDocAugmentsTag = 323, - JSDocImplementsTag = 324, - JSDocDeprecatedTag = 325, - JSDocPublicTag = 326, - JSDocPrivateTag = 327, - JSDocProtectedTag = 328, - JSDocReadonlyTag = 329, - JSDocOverrideTag = 330, - JSDocCallbackTag = 331, - JSDocOverloadTag = 332, - JSDocParameterTag = 333, - JSDocReturnTag = 334, - JSDocThisTag = 335, - JSDocTypeTag = 336, - JSDocTemplateTag = 337, - JSDocTypedefTag = 338, - JSDocSeeTag = 339, - JSDocPropertyTag = 340, - JSDocThrowsTag = 341, - JSDocSatisfiesTag = 342, - JSDocImportTag = 343, - SyntaxList = 344, - JSTypeAliasDeclaration = 345, - JSImportDeclaration = 346, - NotEmittedStatement = 347, - PartiallyEmittedExpression = 348, - SyntheticReferenceExpression = 349, - NotEmittedTypeElement = 350, - Count = 351, + SourceKeyword = 167, + QualifiedName = 168, + ComputedPropertyName = 169, + TypeParameter = 170, + Parameter = 171, + Decorator = 172, + PropertySignature = 173, + PropertyDeclaration = 174, + MethodSignature = 175, + MethodDeclaration = 176, + ClassStaticBlockDeclaration = 177, + Constructor = 178, + GetAccessor = 179, + SetAccessor = 180, + CallSignature = 181, + ConstructSignature = 182, + IndexSignature = 183, + TypePredicate = 184, + TypeReference = 185, + FunctionType = 186, + ConstructorType = 187, + TypeQuery = 188, + TypeLiteral = 189, + ArrayType = 190, + TupleType = 191, + OptionalType = 192, + RestType = 193, + UnionType = 194, + IntersectionType = 195, + ConditionalType = 196, + InferType = 197, + ParenthesizedType = 198, + ThisType = 199, + TypeOperator = 200, + IndexedAccessType = 201, + MappedType = 202, + LiteralType = 203, + NamedTupleMember = 204, + TemplateLiteralType = 205, + TemplateLiteralTypeSpan = 206, + ImportType = 207, + ObjectBindingPattern = 208, + ArrayBindingPattern = 209, + BindingElement = 210, + ArrayLiteralExpression = 211, + ObjectLiteralExpression = 212, + PropertyAccessExpression = 213, + ElementAccessExpression = 214, + CallExpression = 215, + NewExpression = 216, + TaggedTemplateExpression = 217, + TypeAssertionExpression = 218, + ParenthesizedExpression = 219, + FunctionExpression = 220, + ArrowFunction = 221, + DeleteExpression = 222, + TypeOfExpression = 223, + VoidExpression = 224, + AwaitExpression = 225, + PrefixUnaryExpression = 226, + PostfixUnaryExpression = 227, + BinaryExpression = 228, + ConditionalExpression = 229, + TemplateExpression = 230, + YieldExpression = 231, + SpreadElement = 232, + ClassExpression = 233, + OmittedExpression = 234, + ExpressionWithTypeArguments = 235, + AsExpression = 236, + NonNullExpression = 237, + MetaProperty = 238, + SyntheticExpression = 239, + SatisfiesExpression = 240, + TemplateSpan = 241, + SemicolonClassElement = 242, + Block = 243, + EmptyStatement = 244, + VariableStatement = 245, + ExpressionStatement = 246, + IfStatement = 247, + DoStatement = 248, + WhileStatement = 249, + ForStatement = 250, + ForInStatement = 251, + ForOfStatement = 252, + ContinueStatement = 253, + BreakStatement = 254, + ReturnStatement = 255, + WithStatement = 256, + SwitchStatement = 257, + LabeledStatement = 258, + ThrowStatement = 259, + TryStatement = 260, + DebuggerStatement = 261, + VariableDeclaration = 262, + VariableDeclarationList = 263, + FunctionDeclaration = 264, + ClassDeclaration = 265, + InterfaceDeclaration = 266, + TypeAliasDeclaration = 267, + EnumDeclaration = 268, + ModuleDeclaration = 269, + ModuleBlock = 270, + CaseBlock = 271, + NamespaceExportDeclaration = 272, + ImportEqualsDeclaration = 273, + ImportDeclaration = 274, + ImportClause = 275, + NamespaceImport = 276, + NamedImports = 277, + ImportSpecifier = 278, + ExportAssignment = 279, + ExportDeclaration = 280, + NamedExports = 281, + NamespaceExport = 282, + ExportSpecifier = 283, + MissingDeclaration = 284, + ExternalModuleReference = 285, + JsxElement = 286, + JsxSelfClosingElement = 287, + JsxOpeningElement = 288, + JsxClosingElement = 289, + JsxFragment = 290, + JsxOpeningFragment = 291, + JsxClosingFragment = 292, + JsxAttribute = 293, + JsxAttributes = 294, + JsxSpreadAttribute = 295, + JsxExpression = 296, + JsxNamespacedName = 297, + CaseClause = 298, + DefaultClause = 299, + HeritageClause = 300, + CatchClause = 301, + ImportAttributes = 302, + ImportAttribute = 303, + PropertyAssignment = 304, + ShorthandPropertyAssignment = 305, + SpreadAssignment = 306, + EnumMember = 307, + SourceFile = 308, + JSDocTypeExpression = 309, + JSDocNameReference = 310, + JSDocAllType = 311, + JSDocNullableType = 312, + JSDocNonNullableType = 313, + JSDocOptionalType = 314, + JSDocVariadicType = 315, + JSDoc = 316, + JSDocText = 317, + JSDocTypeLiteral = 318, + JSDocSignature = 319, + JSDocLink = 320, + JSDocLinkCode = 321, + JSDocLinkPlain = 322, + JSDocUnknownTag = 323, + JSDocAugmentsTag = 324, + JSDocImplementsTag = 325, + JSDocDeprecatedTag = 326, + JSDocPublicTag = 327, + JSDocPrivateTag = 328, + JSDocProtectedTag = 329, + JSDocReadonlyTag = 330, + JSDocOverrideTag = 331, + JSDocCallbackTag = 332, + JSDocOverloadTag = 333, + JSDocParameterTag = 334, + JSDocReturnTag = 335, + JSDocThisTag = 336, + JSDocTypeTag = 337, + JSDocTemplateTag = 338, + JSDocTypedefTag = 339, + JSDocSeeTag = 340, + JSDocPropertyTag = 341, + JSDocThrowsTag = 342, + JSDocSatisfiesTag = 343, + JSDocImportTag = 344, + SyntaxList = 345, + JSTypeAliasDeclaration = 346, + JSImportDeclaration = 347, + NotEmittedStatement = 348, + PartiallyEmittedExpression = 349, + SyntheticReferenceExpression = 350, + NotEmittedTypeElement = 351, + Count = 352, FirstAssignment = EqualsToken, LastAssignment = CaretEqualsToken, FirstCompoundAssignment = PlusEqualsToken, @@ -360,7 +361,7 @@ export enum SyntaxKind { FirstReservedWord = BreakKeyword, LastReservedWord = WithKeyword, FirstKeyword = BreakKeyword, - LastKeyword = DeferKeyword, + LastKeyword = SourceKeyword, FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypePredicate, @@ -383,7 +384,7 @@ export enum SyntaxKind { FirstJSDocTagNode = JSDocUnknownTag, LastJSDocTagNode = JSDocImportTag, FirstContextualKeyword = AbstractKeyword, - LastContextualKeyword = DeferKeyword, + LastContextualKeyword = SourceKeyword, LastUnaryOperator = TildeToken, FirstTriviaToken = SingleLineCommentTrivia, LastTriviaToken = ConflictMarkerTrivia, diff --git a/packages/typescript/src/enums/syntaxKind.ts b/packages/typescript/src/enums/syntaxKind.ts index 87c2385c7cd47..053eca9442aeb 100644 --- a/packages/typescript/src/enums/syntaxKind.ts +++ b/packages/typescript/src/enums/syntaxKind.ts @@ -168,191 +168,192 @@ export var SyntaxKind: any; SyntaxKind[SyntaxKind["OverrideKeyword"] = 164] = "OverrideKeyword"; SyntaxKind[SyntaxKind["OfKeyword"] = 165] = "OfKeyword"; SyntaxKind[SyntaxKind["DeferKeyword"] = 166] = "DeferKeyword"; - SyntaxKind[SyntaxKind["QualifiedName"] = 167] = "QualifiedName"; - SyntaxKind[SyntaxKind["ComputedPropertyName"] = 168] = "ComputedPropertyName"; - SyntaxKind[SyntaxKind["TypeParameter"] = 169] = "TypeParameter"; - SyntaxKind[SyntaxKind["Parameter"] = 170] = "Parameter"; - SyntaxKind[SyntaxKind["Decorator"] = 171] = "Decorator"; - SyntaxKind[SyntaxKind["PropertySignature"] = 172] = "PropertySignature"; - SyntaxKind[SyntaxKind["PropertyDeclaration"] = 173] = "PropertyDeclaration"; - SyntaxKind[SyntaxKind["MethodSignature"] = 174] = "MethodSignature"; - SyntaxKind[SyntaxKind["MethodDeclaration"] = 175] = "MethodDeclaration"; - SyntaxKind[SyntaxKind["ClassStaticBlockDeclaration"] = 176] = "ClassStaticBlockDeclaration"; - SyntaxKind[SyntaxKind["Constructor"] = 177] = "Constructor"; - SyntaxKind[SyntaxKind["GetAccessor"] = 178] = "GetAccessor"; - SyntaxKind[SyntaxKind["SetAccessor"] = 179] = "SetAccessor"; - SyntaxKind[SyntaxKind["CallSignature"] = 180] = "CallSignature"; - SyntaxKind[SyntaxKind["ConstructSignature"] = 181] = "ConstructSignature"; - SyntaxKind[SyntaxKind["IndexSignature"] = 182] = "IndexSignature"; - SyntaxKind[SyntaxKind["TypePredicate"] = 183] = "TypePredicate"; - SyntaxKind[SyntaxKind["TypeReference"] = 184] = "TypeReference"; - SyntaxKind[SyntaxKind["FunctionType"] = 185] = "FunctionType"; - SyntaxKind[SyntaxKind["ConstructorType"] = 186] = "ConstructorType"; - SyntaxKind[SyntaxKind["TypeQuery"] = 187] = "TypeQuery"; - SyntaxKind[SyntaxKind["TypeLiteral"] = 188] = "TypeLiteral"; - SyntaxKind[SyntaxKind["ArrayType"] = 189] = "ArrayType"; - SyntaxKind[SyntaxKind["TupleType"] = 190] = "TupleType"; - SyntaxKind[SyntaxKind["OptionalType"] = 191] = "OptionalType"; - SyntaxKind[SyntaxKind["RestType"] = 192] = "RestType"; - SyntaxKind[SyntaxKind["UnionType"] = 193] = "UnionType"; - SyntaxKind[SyntaxKind["IntersectionType"] = 194] = "IntersectionType"; - SyntaxKind[SyntaxKind["ConditionalType"] = 195] = "ConditionalType"; - SyntaxKind[SyntaxKind["InferType"] = 196] = "InferType"; - SyntaxKind[SyntaxKind["ParenthesizedType"] = 197] = "ParenthesizedType"; - SyntaxKind[SyntaxKind["ThisType"] = 198] = "ThisType"; - SyntaxKind[SyntaxKind["TypeOperator"] = 199] = "TypeOperator"; - SyntaxKind[SyntaxKind["IndexedAccessType"] = 200] = "IndexedAccessType"; - SyntaxKind[SyntaxKind["MappedType"] = 201] = "MappedType"; - SyntaxKind[SyntaxKind["LiteralType"] = 202] = "LiteralType"; - SyntaxKind[SyntaxKind["NamedTupleMember"] = 203] = "NamedTupleMember"; - SyntaxKind[SyntaxKind["TemplateLiteralType"] = 204] = "TemplateLiteralType"; - SyntaxKind[SyntaxKind["TemplateLiteralTypeSpan"] = 205] = "TemplateLiteralTypeSpan"; - SyntaxKind[SyntaxKind["ImportType"] = 206] = "ImportType"; - SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 207] = "ObjectBindingPattern"; - SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 208] = "ArrayBindingPattern"; - SyntaxKind[SyntaxKind["BindingElement"] = 209] = "BindingElement"; - SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 210] = "ArrayLiteralExpression"; - SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 211] = "ObjectLiteralExpression"; - SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 212] = "PropertyAccessExpression"; - SyntaxKind[SyntaxKind["ElementAccessExpression"] = 213] = "ElementAccessExpression"; - SyntaxKind[SyntaxKind["CallExpression"] = 214] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 215] = "NewExpression"; - SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 216] = "TaggedTemplateExpression"; - SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 217] = "TypeAssertionExpression"; - SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 218] = "ParenthesizedExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 219] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 220] = "ArrowFunction"; - SyntaxKind[SyntaxKind["DeleteExpression"] = 221] = "DeleteExpression"; - SyntaxKind[SyntaxKind["TypeOfExpression"] = 222] = "TypeOfExpression"; - SyntaxKind[SyntaxKind["VoidExpression"] = 223] = "VoidExpression"; - SyntaxKind[SyntaxKind["AwaitExpression"] = 224] = "AwaitExpression"; - SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 225] = "PrefixUnaryExpression"; - SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 226] = "PostfixUnaryExpression"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 227] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 228] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["TemplateExpression"] = 229] = "TemplateExpression"; - SyntaxKind[SyntaxKind["YieldExpression"] = 230] = "YieldExpression"; - SyntaxKind[SyntaxKind["SpreadElement"] = 231] = "SpreadElement"; - SyntaxKind[SyntaxKind["ClassExpression"] = 232] = "ClassExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 233] = "OmittedExpression"; - SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 234] = "ExpressionWithTypeArguments"; - SyntaxKind[SyntaxKind["AsExpression"] = 235] = "AsExpression"; - SyntaxKind[SyntaxKind["NonNullExpression"] = 236] = "NonNullExpression"; - SyntaxKind[SyntaxKind["MetaProperty"] = 237] = "MetaProperty"; - SyntaxKind[SyntaxKind["SyntheticExpression"] = 238] = "SyntheticExpression"; - SyntaxKind[SyntaxKind["SatisfiesExpression"] = 239] = "SatisfiesExpression"; - SyntaxKind[SyntaxKind["TemplateSpan"] = 240] = "TemplateSpan"; - SyntaxKind[SyntaxKind["SemicolonClassElement"] = 241] = "SemicolonClassElement"; - SyntaxKind[SyntaxKind["Block"] = 242] = "Block"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 243] = "EmptyStatement"; - SyntaxKind[SyntaxKind["VariableStatement"] = 244] = "VariableStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 245] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 246] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 247] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 248] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 249] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 250] = "ForInStatement"; - SyntaxKind[SyntaxKind["ForOfStatement"] = 251] = "ForOfStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 252] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 253] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 254] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 255] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 256] = "SwitchStatement"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 257] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 258] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 259] = "TryStatement"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 260] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 261] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["VariableDeclarationList"] = 262] = "VariableDeclarationList"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 263] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 264] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 265] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 266] = "TypeAliasDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 267] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 268] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 269] = "ModuleBlock"; - SyntaxKind[SyntaxKind["CaseBlock"] = 270] = "CaseBlock"; - SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 271] = "NamespaceExportDeclaration"; - SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 272] = "ImportEqualsDeclaration"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 273] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ImportClause"] = 274] = "ImportClause"; - SyntaxKind[SyntaxKind["NamespaceImport"] = 275] = "NamespaceImport"; - SyntaxKind[SyntaxKind["NamedImports"] = 276] = "NamedImports"; - SyntaxKind[SyntaxKind["ImportSpecifier"] = 277] = "ImportSpecifier"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 278] = "ExportAssignment"; - SyntaxKind[SyntaxKind["ExportDeclaration"] = 279] = "ExportDeclaration"; - SyntaxKind[SyntaxKind["NamedExports"] = 280] = "NamedExports"; - SyntaxKind[SyntaxKind["NamespaceExport"] = 281] = "NamespaceExport"; - SyntaxKind[SyntaxKind["ExportSpecifier"] = 282] = "ExportSpecifier"; - SyntaxKind[SyntaxKind["MissingDeclaration"] = 283] = "MissingDeclaration"; - SyntaxKind[SyntaxKind["ExternalModuleReference"] = 284] = "ExternalModuleReference"; - SyntaxKind[SyntaxKind["JsxElement"] = 285] = "JsxElement"; - SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 286] = "JsxSelfClosingElement"; - SyntaxKind[SyntaxKind["JsxOpeningElement"] = 287] = "JsxOpeningElement"; - SyntaxKind[SyntaxKind["JsxClosingElement"] = 288] = "JsxClosingElement"; - SyntaxKind[SyntaxKind["JsxFragment"] = 289] = "JsxFragment"; - SyntaxKind[SyntaxKind["JsxOpeningFragment"] = 290] = "JsxOpeningFragment"; - SyntaxKind[SyntaxKind["JsxClosingFragment"] = 291] = "JsxClosingFragment"; - SyntaxKind[SyntaxKind["JsxAttribute"] = 292] = "JsxAttribute"; - SyntaxKind[SyntaxKind["JsxAttributes"] = 293] = "JsxAttributes"; - SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 294] = "JsxSpreadAttribute"; - SyntaxKind[SyntaxKind["JsxExpression"] = 295] = "JsxExpression"; - SyntaxKind[SyntaxKind["JsxNamespacedName"] = 296] = "JsxNamespacedName"; - SyntaxKind[SyntaxKind["CaseClause"] = 297] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 298] = "DefaultClause"; - SyntaxKind[SyntaxKind["HeritageClause"] = 299] = "HeritageClause"; - SyntaxKind[SyntaxKind["CatchClause"] = 300] = "CatchClause"; - SyntaxKind[SyntaxKind["ImportAttributes"] = 301] = "ImportAttributes"; - SyntaxKind[SyntaxKind["ImportAttribute"] = 302] = "ImportAttribute"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 303] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 304] = "ShorthandPropertyAssignment"; - SyntaxKind[SyntaxKind["SpreadAssignment"] = 305] = "SpreadAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 306] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 307] = "SourceFile"; - SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 308] = "JSDocTypeExpression"; - SyntaxKind[SyntaxKind["JSDocNameReference"] = 309] = "JSDocNameReference"; - SyntaxKind[SyntaxKind["JSDocAllType"] = 310] = "JSDocAllType"; - SyntaxKind[SyntaxKind["JSDocNullableType"] = 311] = "JSDocNullableType"; - SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 312] = "JSDocNonNullableType"; - SyntaxKind[SyntaxKind["JSDocOptionalType"] = 313] = "JSDocOptionalType"; - SyntaxKind[SyntaxKind["JSDocVariadicType"] = 314] = "JSDocVariadicType"; - SyntaxKind[SyntaxKind["JSDoc"] = 315] = "JSDoc"; - SyntaxKind[SyntaxKind["JSDocText"] = 316] = "JSDocText"; - SyntaxKind[SyntaxKind["JSDocTypeLiteral"] = 317] = "JSDocTypeLiteral"; - SyntaxKind[SyntaxKind["JSDocSignature"] = 318] = "JSDocSignature"; - SyntaxKind[SyntaxKind["JSDocLink"] = 319] = "JSDocLink"; - SyntaxKind[SyntaxKind["JSDocLinkCode"] = 320] = "JSDocLinkCode"; - SyntaxKind[SyntaxKind["JSDocLinkPlain"] = 321] = "JSDocLinkPlain"; - SyntaxKind[SyntaxKind["JSDocUnknownTag"] = 322] = "JSDocUnknownTag"; - SyntaxKind[SyntaxKind["JSDocAugmentsTag"] = 323] = "JSDocAugmentsTag"; - SyntaxKind[SyntaxKind["JSDocImplementsTag"] = 324] = "JSDocImplementsTag"; - SyntaxKind[SyntaxKind["JSDocDeprecatedTag"] = 325] = "JSDocDeprecatedTag"; - SyntaxKind[SyntaxKind["JSDocPublicTag"] = 326] = "JSDocPublicTag"; - SyntaxKind[SyntaxKind["JSDocPrivateTag"] = 327] = "JSDocPrivateTag"; - SyntaxKind[SyntaxKind["JSDocProtectedTag"] = 328] = "JSDocProtectedTag"; - SyntaxKind[SyntaxKind["JSDocReadonlyTag"] = 329] = "JSDocReadonlyTag"; - SyntaxKind[SyntaxKind["JSDocOverrideTag"] = 330] = "JSDocOverrideTag"; - SyntaxKind[SyntaxKind["JSDocCallbackTag"] = 331] = "JSDocCallbackTag"; - SyntaxKind[SyntaxKind["JSDocOverloadTag"] = 332] = "JSDocOverloadTag"; - SyntaxKind[SyntaxKind["JSDocParameterTag"] = 333] = "JSDocParameterTag"; - SyntaxKind[SyntaxKind["JSDocReturnTag"] = 334] = "JSDocReturnTag"; - SyntaxKind[SyntaxKind["JSDocThisTag"] = 335] = "JSDocThisTag"; - SyntaxKind[SyntaxKind["JSDocTypeTag"] = 336] = "JSDocTypeTag"; - SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 337] = "JSDocTemplateTag"; - SyntaxKind[SyntaxKind["JSDocTypedefTag"] = 338] = "JSDocTypedefTag"; - SyntaxKind[SyntaxKind["JSDocSeeTag"] = 339] = "JSDocSeeTag"; - SyntaxKind[SyntaxKind["JSDocPropertyTag"] = 340] = "JSDocPropertyTag"; - SyntaxKind[SyntaxKind["JSDocThrowsTag"] = 341] = "JSDocThrowsTag"; - SyntaxKind[SyntaxKind["JSDocSatisfiesTag"] = 342] = "JSDocSatisfiesTag"; - SyntaxKind[SyntaxKind["JSDocImportTag"] = 343] = "JSDocImportTag"; - SyntaxKind[SyntaxKind["SyntaxList"] = 344] = "SyntaxList"; - SyntaxKind[SyntaxKind["JSTypeAliasDeclaration"] = 345] = "JSTypeAliasDeclaration"; - SyntaxKind[SyntaxKind["JSImportDeclaration"] = 346] = "JSImportDeclaration"; - SyntaxKind[SyntaxKind["NotEmittedStatement"] = 347] = "NotEmittedStatement"; - SyntaxKind[SyntaxKind["PartiallyEmittedExpression"] = 348] = "PartiallyEmittedExpression"; - SyntaxKind[SyntaxKind["SyntheticReferenceExpression"] = 349] = "SyntheticReferenceExpression"; - SyntaxKind[SyntaxKind["NotEmittedTypeElement"] = 350] = "NotEmittedTypeElement"; - SyntaxKind[SyntaxKind["Count"] = 351] = "Count"; + SyntaxKind[SyntaxKind["SourceKeyword"] = 167] = "SourceKeyword"; + SyntaxKind[SyntaxKind["QualifiedName"] = 168] = "QualifiedName"; + SyntaxKind[SyntaxKind["ComputedPropertyName"] = 169] = "ComputedPropertyName"; + SyntaxKind[SyntaxKind["TypeParameter"] = 170] = "TypeParameter"; + SyntaxKind[SyntaxKind["Parameter"] = 171] = "Parameter"; + SyntaxKind[SyntaxKind["Decorator"] = 172] = "Decorator"; + SyntaxKind[SyntaxKind["PropertySignature"] = 173] = "PropertySignature"; + SyntaxKind[SyntaxKind["PropertyDeclaration"] = 174] = "PropertyDeclaration"; + SyntaxKind[SyntaxKind["MethodSignature"] = 175] = "MethodSignature"; + SyntaxKind[SyntaxKind["MethodDeclaration"] = 176] = "MethodDeclaration"; + SyntaxKind[SyntaxKind["ClassStaticBlockDeclaration"] = 177] = "ClassStaticBlockDeclaration"; + SyntaxKind[SyntaxKind["Constructor"] = 178] = "Constructor"; + SyntaxKind[SyntaxKind["GetAccessor"] = 179] = "GetAccessor"; + SyntaxKind[SyntaxKind["SetAccessor"] = 180] = "SetAccessor"; + SyntaxKind[SyntaxKind["CallSignature"] = 181] = "CallSignature"; + SyntaxKind[SyntaxKind["ConstructSignature"] = 182] = "ConstructSignature"; + SyntaxKind[SyntaxKind["IndexSignature"] = 183] = "IndexSignature"; + SyntaxKind[SyntaxKind["TypePredicate"] = 184] = "TypePredicate"; + SyntaxKind[SyntaxKind["TypeReference"] = 185] = "TypeReference"; + SyntaxKind[SyntaxKind["FunctionType"] = 186] = "FunctionType"; + SyntaxKind[SyntaxKind["ConstructorType"] = 187] = "ConstructorType"; + SyntaxKind[SyntaxKind["TypeQuery"] = 188] = "TypeQuery"; + SyntaxKind[SyntaxKind["TypeLiteral"] = 189] = "TypeLiteral"; + SyntaxKind[SyntaxKind["ArrayType"] = 190] = "ArrayType"; + SyntaxKind[SyntaxKind["TupleType"] = 191] = "TupleType"; + SyntaxKind[SyntaxKind["OptionalType"] = 192] = "OptionalType"; + SyntaxKind[SyntaxKind["RestType"] = 193] = "RestType"; + SyntaxKind[SyntaxKind["UnionType"] = 194] = "UnionType"; + SyntaxKind[SyntaxKind["IntersectionType"] = 195] = "IntersectionType"; + SyntaxKind[SyntaxKind["ConditionalType"] = 196] = "ConditionalType"; + SyntaxKind[SyntaxKind["InferType"] = 197] = "InferType"; + SyntaxKind[SyntaxKind["ParenthesizedType"] = 198] = "ParenthesizedType"; + SyntaxKind[SyntaxKind["ThisType"] = 199] = "ThisType"; + SyntaxKind[SyntaxKind["TypeOperator"] = 200] = "TypeOperator"; + SyntaxKind[SyntaxKind["IndexedAccessType"] = 201] = "IndexedAccessType"; + SyntaxKind[SyntaxKind["MappedType"] = 202] = "MappedType"; + SyntaxKind[SyntaxKind["LiteralType"] = 203] = "LiteralType"; + SyntaxKind[SyntaxKind["NamedTupleMember"] = 204] = "NamedTupleMember"; + SyntaxKind[SyntaxKind["TemplateLiteralType"] = 205] = "TemplateLiteralType"; + SyntaxKind[SyntaxKind["TemplateLiteralTypeSpan"] = 206] = "TemplateLiteralTypeSpan"; + SyntaxKind[SyntaxKind["ImportType"] = 207] = "ImportType"; + SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 208] = "ObjectBindingPattern"; + SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 209] = "ArrayBindingPattern"; + SyntaxKind[SyntaxKind["BindingElement"] = 210] = "BindingElement"; + SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 211] = "ArrayLiteralExpression"; + SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 212] = "ObjectLiteralExpression"; + SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 213] = "PropertyAccessExpression"; + SyntaxKind[SyntaxKind["ElementAccessExpression"] = 214] = "ElementAccessExpression"; + SyntaxKind[SyntaxKind["CallExpression"] = 215] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 216] = "NewExpression"; + SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 217] = "TaggedTemplateExpression"; + SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 218] = "TypeAssertionExpression"; + SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 219] = "ParenthesizedExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 220] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 221] = "ArrowFunction"; + SyntaxKind[SyntaxKind["DeleteExpression"] = 222] = "DeleteExpression"; + SyntaxKind[SyntaxKind["TypeOfExpression"] = 223] = "TypeOfExpression"; + SyntaxKind[SyntaxKind["VoidExpression"] = 224] = "VoidExpression"; + SyntaxKind[SyntaxKind["AwaitExpression"] = 225] = "AwaitExpression"; + SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 226] = "PrefixUnaryExpression"; + SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 227] = "PostfixUnaryExpression"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 228] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 229] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["TemplateExpression"] = 230] = "TemplateExpression"; + SyntaxKind[SyntaxKind["YieldExpression"] = 231] = "YieldExpression"; + SyntaxKind[SyntaxKind["SpreadElement"] = 232] = "SpreadElement"; + SyntaxKind[SyntaxKind["ClassExpression"] = 233] = "ClassExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 234] = "OmittedExpression"; + SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 235] = "ExpressionWithTypeArguments"; + SyntaxKind[SyntaxKind["AsExpression"] = 236] = "AsExpression"; + SyntaxKind[SyntaxKind["NonNullExpression"] = 237] = "NonNullExpression"; + SyntaxKind[SyntaxKind["MetaProperty"] = 238] = "MetaProperty"; + SyntaxKind[SyntaxKind["SyntheticExpression"] = 239] = "SyntheticExpression"; + SyntaxKind[SyntaxKind["SatisfiesExpression"] = 240] = "SatisfiesExpression"; + SyntaxKind[SyntaxKind["TemplateSpan"] = 241] = "TemplateSpan"; + SyntaxKind[SyntaxKind["SemicolonClassElement"] = 242] = "SemicolonClassElement"; + SyntaxKind[SyntaxKind["Block"] = 243] = "Block"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 244] = "EmptyStatement"; + SyntaxKind[SyntaxKind["VariableStatement"] = 245] = "VariableStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 246] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 247] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 248] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 249] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 250] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 251] = "ForInStatement"; + SyntaxKind[SyntaxKind["ForOfStatement"] = 252] = "ForOfStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 253] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 254] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 255] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 256] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 257] = "SwitchStatement"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 258] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 259] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 260] = "TryStatement"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 261] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 262] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["VariableDeclarationList"] = 263] = "VariableDeclarationList"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 264] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 265] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 266] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 267] = "TypeAliasDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 268] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 269] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 270] = "ModuleBlock"; + SyntaxKind[SyntaxKind["CaseBlock"] = 271] = "CaseBlock"; + SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 272] = "NamespaceExportDeclaration"; + SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 273] = "ImportEqualsDeclaration"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 274] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ImportClause"] = 275] = "ImportClause"; + SyntaxKind[SyntaxKind["NamespaceImport"] = 276] = "NamespaceImport"; + SyntaxKind[SyntaxKind["NamedImports"] = 277] = "NamedImports"; + SyntaxKind[SyntaxKind["ImportSpecifier"] = 278] = "ImportSpecifier"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 279] = "ExportAssignment"; + SyntaxKind[SyntaxKind["ExportDeclaration"] = 280] = "ExportDeclaration"; + SyntaxKind[SyntaxKind["NamedExports"] = 281] = "NamedExports"; + SyntaxKind[SyntaxKind["NamespaceExport"] = 282] = "NamespaceExport"; + SyntaxKind[SyntaxKind["ExportSpecifier"] = 283] = "ExportSpecifier"; + SyntaxKind[SyntaxKind["MissingDeclaration"] = 284] = "MissingDeclaration"; + SyntaxKind[SyntaxKind["ExternalModuleReference"] = 285] = "ExternalModuleReference"; + SyntaxKind[SyntaxKind["JsxElement"] = 286] = "JsxElement"; + SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 287] = "JsxSelfClosingElement"; + SyntaxKind[SyntaxKind["JsxOpeningElement"] = 288] = "JsxOpeningElement"; + SyntaxKind[SyntaxKind["JsxClosingElement"] = 289] = "JsxClosingElement"; + SyntaxKind[SyntaxKind["JsxFragment"] = 290] = "JsxFragment"; + SyntaxKind[SyntaxKind["JsxOpeningFragment"] = 291] = "JsxOpeningFragment"; + SyntaxKind[SyntaxKind["JsxClosingFragment"] = 292] = "JsxClosingFragment"; + SyntaxKind[SyntaxKind["JsxAttribute"] = 293] = "JsxAttribute"; + SyntaxKind[SyntaxKind["JsxAttributes"] = 294] = "JsxAttributes"; + SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 295] = "JsxSpreadAttribute"; + SyntaxKind[SyntaxKind["JsxExpression"] = 296] = "JsxExpression"; + SyntaxKind[SyntaxKind["JsxNamespacedName"] = 297] = "JsxNamespacedName"; + SyntaxKind[SyntaxKind["CaseClause"] = 298] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 299] = "DefaultClause"; + SyntaxKind[SyntaxKind["HeritageClause"] = 300] = "HeritageClause"; + SyntaxKind[SyntaxKind["CatchClause"] = 301] = "CatchClause"; + SyntaxKind[SyntaxKind["ImportAttributes"] = 302] = "ImportAttributes"; + SyntaxKind[SyntaxKind["ImportAttribute"] = 303] = "ImportAttribute"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 304] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 305] = "ShorthandPropertyAssignment"; + SyntaxKind[SyntaxKind["SpreadAssignment"] = 306] = "SpreadAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 307] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 308] = "SourceFile"; + SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 309] = "JSDocTypeExpression"; + SyntaxKind[SyntaxKind["JSDocNameReference"] = 310] = "JSDocNameReference"; + SyntaxKind[SyntaxKind["JSDocAllType"] = 311] = "JSDocAllType"; + SyntaxKind[SyntaxKind["JSDocNullableType"] = 312] = "JSDocNullableType"; + SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 313] = "JSDocNonNullableType"; + SyntaxKind[SyntaxKind["JSDocOptionalType"] = 314] = "JSDocOptionalType"; + SyntaxKind[SyntaxKind["JSDocVariadicType"] = 315] = "JSDocVariadicType"; + SyntaxKind[SyntaxKind["JSDoc"] = 316] = "JSDoc"; + SyntaxKind[SyntaxKind["JSDocText"] = 317] = "JSDocText"; + SyntaxKind[SyntaxKind["JSDocTypeLiteral"] = 318] = "JSDocTypeLiteral"; + SyntaxKind[SyntaxKind["JSDocSignature"] = 319] = "JSDocSignature"; + SyntaxKind[SyntaxKind["JSDocLink"] = 320] = "JSDocLink"; + SyntaxKind[SyntaxKind["JSDocLinkCode"] = 321] = "JSDocLinkCode"; + SyntaxKind[SyntaxKind["JSDocLinkPlain"] = 322] = "JSDocLinkPlain"; + SyntaxKind[SyntaxKind["JSDocUnknownTag"] = 323] = "JSDocUnknownTag"; + SyntaxKind[SyntaxKind["JSDocAugmentsTag"] = 324] = "JSDocAugmentsTag"; + SyntaxKind[SyntaxKind["JSDocImplementsTag"] = 325] = "JSDocImplementsTag"; + SyntaxKind[SyntaxKind["JSDocDeprecatedTag"] = 326] = "JSDocDeprecatedTag"; + SyntaxKind[SyntaxKind["JSDocPublicTag"] = 327] = "JSDocPublicTag"; + SyntaxKind[SyntaxKind["JSDocPrivateTag"] = 328] = "JSDocPrivateTag"; + SyntaxKind[SyntaxKind["JSDocProtectedTag"] = 329] = "JSDocProtectedTag"; + SyntaxKind[SyntaxKind["JSDocReadonlyTag"] = 330] = "JSDocReadonlyTag"; + SyntaxKind[SyntaxKind["JSDocOverrideTag"] = 331] = "JSDocOverrideTag"; + SyntaxKind[SyntaxKind["JSDocCallbackTag"] = 332] = "JSDocCallbackTag"; + SyntaxKind[SyntaxKind["JSDocOverloadTag"] = 333] = "JSDocOverloadTag"; + SyntaxKind[SyntaxKind["JSDocParameterTag"] = 334] = "JSDocParameterTag"; + SyntaxKind[SyntaxKind["JSDocReturnTag"] = 335] = "JSDocReturnTag"; + SyntaxKind[SyntaxKind["JSDocThisTag"] = 336] = "JSDocThisTag"; + SyntaxKind[SyntaxKind["JSDocTypeTag"] = 337] = "JSDocTypeTag"; + SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 338] = "JSDocTemplateTag"; + SyntaxKind[SyntaxKind["JSDocTypedefTag"] = 339] = "JSDocTypedefTag"; + SyntaxKind[SyntaxKind["JSDocSeeTag"] = 340] = "JSDocSeeTag"; + SyntaxKind[SyntaxKind["JSDocPropertyTag"] = 341] = "JSDocPropertyTag"; + SyntaxKind[SyntaxKind["JSDocThrowsTag"] = 342] = "JSDocThrowsTag"; + SyntaxKind[SyntaxKind["JSDocSatisfiesTag"] = 343] = "JSDocSatisfiesTag"; + SyntaxKind[SyntaxKind["JSDocImportTag"] = 344] = "JSDocImportTag"; + SyntaxKind[SyntaxKind["SyntaxList"] = 345] = "SyntaxList"; + SyntaxKind[SyntaxKind["JSTypeAliasDeclaration"] = 346] = "JSTypeAliasDeclaration"; + SyntaxKind[SyntaxKind["JSImportDeclaration"] = 347] = "JSImportDeclaration"; + SyntaxKind[SyntaxKind["NotEmittedStatement"] = 348] = "NotEmittedStatement"; + SyntaxKind[SyntaxKind["PartiallyEmittedExpression"] = 349] = "PartiallyEmittedExpression"; + SyntaxKind[SyntaxKind["SyntheticReferenceExpression"] = 350] = "SyntheticReferenceExpression"; + SyntaxKind[SyntaxKind["NotEmittedTypeElement"] = 351] = "NotEmittedTypeElement"; + SyntaxKind[SyntaxKind["Count"] = 352] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = 63] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = 78] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstCompoundAssignment"] = 64] = "FirstCompoundAssignment"; @@ -360,30 +361,30 @@ export var SyntaxKind: any; SyntaxKind[SyntaxKind["FirstReservedWord"] = 82] = "FirstReservedWord"; SyntaxKind[SyntaxKind["LastReservedWord"] = 117] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 82] = "FirstKeyword"; - SyntaxKind[SyntaxKind["LastKeyword"] = 166] = "LastKeyword"; + SyntaxKind[SyntaxKind["LastKeyword"] = 167] = "LastKeyword"; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 118] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 126] = "LastFutureReservedWord"; - SyntaxKind[SyntaxKind["FirstTypeNode"] = 183] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = 206] = "LastTypeNode"; + SyntaxKind[SyntaxKind["FirstTypeNode"] = 184] = "FirstTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = 207] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 18] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = 78] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken"; - SyntaxKind[SyntaxKind["LastToken"] = 166] = "LastToken"; + SyntaxKind[SyntaxKind["LastToken"] = 167] = "LastToken"; SyntaxKind[SyntaxKind["FirstLiteralToken"] = 8] = "FirstLiteralToken"; SyntaxKind[SyntaxKind["LastLiteralToken"] = 14] = "LastLiteralToken"; SyntaxKind[SyntaxKind["FirstTemplateToken"] = 14] = "FirstTemplateToken"; SyntaxKind[SyntaxKind["LastTemplateToken"] = 17] = "LastTemplateToken"; SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 29] = "FirstBinaryOperator"; SyntaxKind[SyntaxKind["LastBinaryOperator"] = 78] = "LastBinaryOperator"; - SyntaxKind[SyntaxKind["FirstStatement"] = 244] = "FirstStatement"; - SyntaxKind[SyntaxKind["LastStatement"] = 260] = "LastStatement"; - SyntaxKind[SyntaxKind["FirstNode"] = 167] = "FirstNode"; - SyntaxKind[SyntaxKind["FirstJSDocNode"] = 308] = "FirstJSDocNode"; - SyntaxKind[SyntaxKind["LastJSDocNode"] = 343] = "LastJSDocNode"; - SyntaxKind[SyntaxKind["FirstJSDocTagNode"] = 322] = "FirstJSDocTagNode"; - SyntaxKind[SyntaxKind["LastJSDocTagNode"] = 343] = "LastJSDocTagNode"; + SyntaxKind[SyntaxKind["FirstStatement"] = 245] = "FirstStatement"; + SyntaxKind[SyntaxKind["LastStatement"] = 261] = "LastStatement"; + SyntaxKind[SyntaxKind["FirstNode"] = 168] = "FirstNode"; + SyntaxKind[SyntaxKind["FirstJSDocNode"] = 309] = "FirstJSDocNode"; + SyntaxKind[SyntaxKind["LastJSDocNode"] = 344] = "LastJSDocNode"; + SyntaxKind[SyntaxKind["FirstJSDocTagNode"] = 323] = "FirstJSDocTagNode"; + SyntaxKind[SyntaxKind["LastJSDocTagNode"] = 344] = "LastJSDocTagNode"; SyntaxKind[SyntaxKind["FirstContextualKeyword"] = 127] = "FirstContextualKeyword"; - SyntaxKind[SyntaxKind["LastContextualKeyword"] = 166] = "LastContextualKeyword"; + SyntaxKind[SyntaxKind["LastContextualKeyword"] = 167] = "LastContextualKeyword"; SyntaxKind[SyntaxKind["LastUnaryOperator"] = 54] = "LastUnaryOperator"; SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken"; SyntaxKind[SyntaxKind["LastTriviaToken"] = 6] = "LastTriviaToken"; diff --git a/tools/scripts/tsc/ast.json b/tools/scripts/tsc/ast.json index 3c85511b463db..2ec005ded6f1e 100644 --- a/tools/scripts/tsc/ast.json +++ b/tools/scripts/tsc/ast.json @@ -195,8 +195,9 @@ "BigIntKeyword", "OverrideKeyword", "OfKeyword", + "DeferKeyword", { - "name": "DeferKeyword", + "name": "SourceKeyword", "comment": "LastKeyword and LastToken and LastContextualKeyword" }, { @@ -478,7 +479,7 @@ }, { "name": "LastKeyword", - "value": "DeferKeyword" + "value": "SourceKeyword" }, { "name": "FirstFutureReservedWord", @@ -570,7 +571,7 @@ }, { "name": "LastContextualKeyword", - "value": "DeferKeyword" + "value": "SourceKeyword" }, { "name": "LastUnaryOperator", @@ -678,7 +679,8 @@ }, "ImportPhaseModifierSyntaxKind": [ "TypeKeyword", - "DeferKeyword" + "DeferKeyword", + "SourceKeyword" ], "PostfixUnaryOperator": [ "PlusPlusToken", diff --git a/tsc/internal/api/encoder/decoder_generated.go b/tsc/internal/api/encoder/decoder_generated.go index 6532a5a36ee05..77f20975d4dd3 100644 --- a/tsc/internal/api/encoder/decoder_generated.go +++ b/tsc/internal/api/encoder/decoder_generated.go @@ -210,7 +210,8 @@ func (d *astDecoder) createChildrenNode(kind ast.Kind, data uint32, childIndices ast.KindGlobalKeyword, ast.KindOverrideKeyword, ast.KindOfKeyword, - ast.KindDeferKeyword: + ast.KindDeferKeyword, + ast.KindSourceKeyword: return d.factory.NewToken(kind), nil case ast.KindQualifiedName: it := newChildIter(childIndices) @@ -1094,6 +1095,8 @@ func (d *astDecoder) createChildrenNode(kind ast.Kind, data uint32, childIndices phaseModifier = ast.KindTypeKeyword case 2: phaseModifier = ast.KindDeferKeyword + case 3: + phaseModifier = ast.KindSourceKeyword } it := newChildIter(childIndices) name := d.nodeAt(it.nextIf(mask, 0)) diff --git a/tsc/internal/api/encoder/decoder_test.go b/tsc/internal/api/encoder/decoder_test.go index 26f6a95830a9e..2f3d9dc83b508 100644 --- a/tsc/internal/api/encoder/decoder_test.go +++ b/tsc/internal/api/encoder/decoder_test.go @@ -147,6 +147,20 @@ func TestDecodeSourceFile_ImportDeclaration(t *testing.T) { assert.Equal(t, spec.Name().AsIdentifier().Text, "bar") } +func TestDecodeSourceFile_SourcePhaseImport(t *testing.T) { + t.Parallel() + sf := parseSourceFile(`import source a from "./a.wasm";`) + buf, _, err := encoder.EncodeSourceFile(sf) + assert.NilError(t, err) + + decoded, err := encoder.DecodeSourceFile(buf) + assert.NilError(t, err) + + clause := decoded.Statements.Nodes[0].AsImportDeclaration().ImportClause.AsImportClause() + assert.Equal(t, clause.PhaseModifier, ast.KindSourceKeyword) + assert.Equal(t, clause.Name().Text(), "a") +} + func TestDecodeSourceFile_IfStatement(t *testing.T) { t.Parallel() sf := parseSourceFile("if (true) { } else { }") diff --git a/tsc/internal/api/encoder/encoder_generated.go b/tsc/internal/api/encoder/encoder_generated.go index d3e7599e326c7..7295e0e84e1db 100644 --- a/tsc/internal/api/encoder/encoder_generated.go +++ b/tsc/internal/api/encoder/encoder_generated.go @@ -643,6 +643,8 @@ func getNodeCommonData(node *ast.Node) uint32 { phaseModifierIdx = 1 case ast.KindDeferKeyword: phaseModifierIdx = 2 + case ast.KindSourceKeyword: + phaseModifierIdx = 3 } return phaseModifierIdx << 24 case ast.KindImportSpecifier: diff --git a/tsc/internal/ast/ast.go b/tsc/internal/ast/ast.go index 07b0fdc62c644..693d872039ca9 100644 --- a/tsc/internal/ast/ast.go +++ b/tsc/internal/ast/ast.go @@ -2130,7 +2130,7 @@ func (node *CallExpression) computeSubtreeFacts() SubtreeFacts { propagateSubtreeFacts(node.QuestionDotToken) | propagateEraseableSyntaxListSubtreeFacts(node.TypeArguments) | propagateNodeListSubtreeFacts(node.Arguments, propagateSubtreeFacts) | - core.IfElse(node.Expression.Kind == KindImportKeyword, SubtreeContainsDynamicImport, SubtreeFactsNone) + core.IfElse(IsImportCall(node.AsNode()), SubtreeContainsDynamicImport, SubtreeFactsNone) } func (node *CallExpression) propagateSubtreeFacts() SubtreeFacts { diff --git a/tsc/internal/ast/ast_generated.go b/tsc/internal/ast/ast_generated.go index 87c1e59f8653e..dba15940c7a3c 100644 --- a/tsc/internal/ast/ast_generated.go +++ b/tsc/internal/ast/ast_generated.go @@ -608,7 +608,7 @@ func (node *Token) Clone(f NodeFactoryCoercible) *Node { func IsToken(node *Node) bool { switch node.Kind { - case KindUnknown, KindEndOfFile, KindSingleLineCommentTrivia, KindMultiLineCommentTrivia, KindNewLineTrivia, KindWhitespaceTrivia, KindConflictMarkerTrivia, KindNonTextFileMarkerTrivia, KindNumericLiteral, KindBigIntLiteral, KindStringLiteral, KindJsxText, KindJsxTextAllWhiteSpaces, KindRegularExpressionLiteral, KindNoSubstitutionTemplateLiteral, KindTemplateHead, KindTemplateMiddle, KindTemplateTail, KindOpenBraceToken, KindCloseBraceToken, KindOpenParenToken, KindCloseParenToken, KindOpenBracketToken, KindCloseBracketToken, KindDotToken, KindDotDotDotToken, KindSemicolonToken, KindCommaToken, KindQuestionDotToken, KindLessThanToken, KindLessThanSlashToken, KindGreaterThanToken, KindLessThanEqualsToken, KindGreaterThanEqualsToken, KindEqualsEqualsToken, KindExclamationEqualsToken, KindEqualsEqualsEqualsToken, KindExclamationEqualsEqualsToken, KindEqualsGreaterThanToken, KindPlusToken, KindMinusToken, KindAsteriskToken, KindAsteriskAsteriskToken, KindSlashToken, KindPercentToken, KindPlusPlusToken, KindMinusMinusToken, KindLessThanLessThanToken, KindGreaterThanGreaterThanToken, KindGreaterThanGreaterThanGreaterThanToken, KindAmpersandToken, KindBarToken, KindCaretToken, KindExclamationToken, KindTildeToken, KindAmpersandAmpersandToken, KindBarBarToken, KindQuestionToken, KindColonToken, KindAtToken, KindQuestionQuestionToken, KindBacktickToken, KindHashToken, KindEqualsToken, KindPlusEqualsToken, KindMinusEqualsToken, KindAsteriskEqualsToken, KindAsteriskAsteriskEqualsToken, KindSlashEqualsToken, KindPercentEqualsToken, KindLessThanLessThanEqualsToken, KindGreaterThanGreaterThanEqualsToken, KindGreaterThanGreaterThanGreaterThanEqualsToken, KindAmpersandEqualsToken, KindBarEqualsToken, KindBarBarEqualsToken, KindAmpersandAmpersandEqualsToken, KindQuestionQuestionEqualsToken, KindCaretEqualsToken, KindIdentifier, KindPrivateIdentifier, KindJSDocCommentTextToken, KindBreakKeyword, KindCaseKeyword, KindCatchKeyword, KindClassKeyword, KindConstKeyword, KindContinueKeyword, KindDebuggerKeyword, KindDefaultKeyword, KindDeleteKeyword, KindDoKeyword, KindElseKeyword, KindEnumKeyword, KindExportKeyword, KindExtendsKeyword, KindFalseKeyword, KindFinallyKeyword, KindForKeyword, KindFunctionKeyword, KindIfKeyword, KindImportKeyword, KindInKeyword, KindInstanceOfKeyword, KindNewKeyword, KindNullKeyword, KindReturnKeyword, KindSuperKeyword, KindSwitchKeyword, KindThisKeyword, KindThrowKeyword, KindTrueKeyword, KindTryKeyword, KindTypeOfKeyword, KindVarKeyword, KindVoidKeyword, KindWhileKeyword, KindWithKeyword, KindImplementsKeyword, KindInterfaceKeyword, KindLetKeyword, KindPackageKeyword, KindPrivateKeyword, KindProtectedKeyword, KindPublicKeyword, KindStaticKeyword, KindYieldKeyword, KindAbstractKeyword, KindAccessorKeyword, KindAsKeyword, KindAssertsKeyword, KindAssertKeyword, KindAnyKeyword, KindAsyncKeyword, KindAwaitKeyword, KindBooleanKeyword, KindConstructorKeyword, KindDeclareKeyword, KindGetKeyword, KindImmediateKeyword, KindInferKeyword, KindIntrinsicKeyword, KindIsKeyword, KindKeyOfKeyword, KindModuleKeyword, KindNamespaceKeyword, KindNeverKeyword, KindOutKeyword, KindReadonlyKeyword, KindRequireKeyword, KindNumberKeyword, KindObjectKeyword, KindSatisfiesKeyword, KindSetKeyword, KindStringKeyword, KindSymbolKeyword, KindTypeKeyword, KindUndefinedKeyword, KindUniqueKeyword, KindUnknownKeyword, KindUsingKeyword, KindFromKeyword, KindGlobalKeyword, KindBigIntKeyword, KindOverrideKeyword, KindOfKeyword, KindDeferKeyword: + case KindUnknown, KindEndOfFile, KindSingleLineCommentTrivia, KindMultiLineCommentTrivia, KindNewLineTrivia, KindWhitespaceTrivia, KindConflictMarkerTrivia, KindNonTextFileMarkerTrivia, KindNumericLiteral, KindBigIntLiteral, KindStringLiteral, KindJsxText, KindJsxTextAllWhiteSpaces, KindRegularExpressionLiteral, KindNoSubstitutionTemplateLiteral, KindTemplateHead, KindTemplateMiddle, KindTemplateTail, KindOpenBraceToken, KindCloseBraceToken, KindOpenParenToken, KindCloseParenToken, KindOpenBracketToken, KindCloseBracketToken, KindDotToken, KindDotDotDotToken, KindSemicolonToken, KindCommaToken, KindQuestionDotToken, KindLessThanToken, KindLessThanSlashToken, KindGreaterThanToken, KindLessThanEqualsToken, KindGreaterThanEqualsToken, KindEqualsEqualsToken, KindExclamationEqualsToken, KindEqualsEqualsEqualsToken, KindExclamationEqualsEqualsToken, KindEqualsGreaterThanToken, KindPlusToken, KindMinusToken, KindAsteriskToken, KindAsteriskAsteriskToken, KindSlashToken, KindPercentToken, KindPlusPlusToken, KindMinusMinusToken, KindLessThanLessThanToken, KindGreaterThanGreaterThanToken, KindGreaterThanGreaterThanGreaterThanToken, KindAmpersandToken, KindBarToken, KindCaretToken, KindExclamationToken, KindTildeToken, KindAmpersandAmpersandToken, KindBarBarToken, KindQuestionToken, KindColonToken, KindAtToken, KindQuestionQuestionToken, KindBacktickToken, KindHashToken, KindEqualsToken, KindPlusEqualsToken, KindMinusEqualsToken, KindAsteriskEqualsToken, KindAsteriskAsteriskEqualsToken, KindSlashEqualsToken, KindPercentEqualsToken, KindLessThanLessThanEqualsToken, KindGreaterThanGreaterThanEqualsToken, KindGreaterThanGreaterThanGreaterThanEqualsToken, KindAmpersandEqualsToken, KindBarEqualsToken, KindBarBarEqualsToken, KindAmpersandAmpersandEqualsToken, KindQuestionQuestionEqualsToken, KindCaretEqualsToken, KindIdentifier, KindPrivateIdentifier, KindJSDocCommentTextToken, KindBreakKeyword, KindCaseKeyword, KindCatchKeyword, KindClassKeyword, KindConstKeyword, KindContinueKeyword, KindDebuggerKeyword, KindDefaultKeyword, KindDeleteKeyword, KindDoKeyword, KindElseKeyword, KindEnumKeyword, KindExportKeyword, KindExtendsKeyword, KindFalseKeyword, KindFinallyKeyword, KindForKeyword, KindFunctionKeyword, KindIfKeyword, KindImportKeyword, KindInKeyword, KindInstanceOfKeyword, KindNewKeyword, KindNullKeyword, KindReturnKeyword, KindSuperKeyword, KindSwitchKeyword, KindThisKeyword, KindThrowKeyword, KindTrueKeyword, KindTryKeyword, KindTypeOfKeyword, KindVarKeyword, KindVoidKeyword, KindWhileKeyword, KindWithKeyword, KindImplementsKeyword, KindInterfaceKeyword, KindLetKeyword, KindPackageKeyword, KindPrivateKeyword, KindProtectedKeyword, KindPublicKeyword, KindStaticKeyword, KindYieldKeyword, KindAbstractKeyword, KindAccessorKeyword, KindAsKeyword, KindAssertsKeyword, KindAssertKeyword, KindAnyKeyword, KindAsyncKeyword, KindAwaitKeyword, KindBooleanKeyword, KindConstructorKeyword, KindDeclareKeyword, KindGetKeyword, KindImmediateKeyword, KindInferKeyword, KindIntrinsicKeyword, KindIsKeyword, KindKeyOfKeyword, KindModuleKeyword, KindNamespaceKeyword, KindNeverKeyword, KindOutKeyword, KindReadonlyKeyword, KindRequireKeyword, KindNumberKeyword, KindObjectKeyword, KindSatisfiesKeyword, KindSetKeyword, KindStringKeyword, KindSymbolKeyword, KindTypeKeyword, KindUndefinedKeyword, KindUniqueKeyword, KindUnknownKeyword, KindUsingKeyword, KindFromKeyword, KindGlobalKeyword, KindBigIntKeyword, KindOverrideKeyword, KindOfKeyword, KindDeferKeyword, KindSourceKeyword: return true } return false @@ -9870,7 +9870,7 @@ func IsJSDocNodeKind(kind Kind) bool { func IsImportPhaseModifierKind(kind Kind) bool { switch kind { - case KindTypeKeyword, KindDeferKeyword: + case KindTypeKeyword, KindDeferKeyword, KindSourceKeyword: return true } return false diff --git a/tsc/internal/ast/kind_generated.go b/tsc/internal/ast/kind_generated.go index 8c67e7947572f..81c2c144c2916 100644 --- a/tsc/internal/ast/kind_generated.go +++ b/tsc/internal/ast/kind_generated.go @@ -183,7 +183,8 @@ const ( KindBigIntKeyword KindOverrideKeyword KindOfKeyword - KindDeferKeyword // LastKeyword and LastToken and LastContextualKeyword + KindDeferKeyword + KindSourceKeyword // LastKeyword and LastToken and LastContextualKeyword // Parse tree nodes // Names KindQualifiedName @@ -396,7 +397,7 @@ const ( KindFirstReservedWord = KindBreakKeyword KindLastReservedWord = KindWithKeyword KindFirstKeyword = KindBreakKeyword - KindLastKeyword = KindDeferKeyword + KindLastKeyword = KindSourceKeyword KindFirstFutureReservedWord = KindImplementsKeyword KindLastFutureReservedWord = KindYieldKeyword KindFirstTypeNode = KindTypePredicate @@ -419,7 +420,7 @@ const ( KindFirstJSDocTagNode = KindJSDocUnknownTag KindLastJSDocTagNode = KindJSDocImportTag KindFirstContextualKeyword = KindAbstractKeyword - KindLastContextualKeyword = KindDeferKeyword + KindLastContextualKeyword = KindSourceKeyword KindLastUnaryOperator = KindTildeToken KindFirstTriviaToken = KindSingleLineCommentTrivia KindLastTriviaToken = KindConflictMarkerTrivia @@ -430,14 +431,14 @@ type ( LiteralSyntaxKind = Kind // KindNumericLiteral | KindBigIntLiteral | KindStringLiteral | KindJsxText | KindJsxTextAllWhiteSpaces | KindRegularExpressionLiteral | KindNoSubstitutionTemplateLiteral PseudoLiteralSyntaxKind = Kind // KindTemplateHead | KindTemplateMiddle | KindTemplateTail PunctuationSyntaxKind = Kind // KindOpenBraceToken | KindCloseBraceToken | KindOpenParenToken | KindCloseParenToken | KindOpenBracketToken | KindCloseBracketToken | KindDotToken | KindDotDotDotToken | KindSemicolonToken | KindCommaToken | KindQuestionDotToken | KindLessThanToken | KindLessThanSlashToken | KindGreaterThanToken | KindLessThanEqualsToken | KindGreaterThanEqualsToken | KindEqualsEqualsToken | KindExclamationEqualsToken | KindEqualsEqualsEqualsToken | KindExclamationEqualsEqualsToken | KindEqualsGreaterThanToken | KindPlusToken | KindMinusToken | KindAsteriskToken | KindAsteriskAsteriskToken | KindSlashToken | KindPercentToken | KindPlusPlusToken | KindMinusMinusToken | KindLessThanLessThanToken | KindGreaterThanGreaterThanToken | KindGreaterThanGreaterThanGreaterThanToken | KindAmpersandToken | KindBarToken | KindCaretToken | KindExclamationToken | KindTildeToken | KindAmpersandAmpersandToken | KindBarBarToken | KindQuestionToken | KindColonToken | KindAtToken | KindQuestionQuestionToken | KindBacktickToken | KindHashToken | KindEqualsToken | KindPlusEqualsToken | KindMinusEqualsToken | KindAsteriskEqualsToken | KindAsteriskAsteriskEqualsToken | KindSlashEqualsToken | KindPercentEqualsToken | KindLessThanLessThanEqualsToken | KindGreaterThanGreaterThanEqualsToken | KindGreaterThanGreaterThanGreaterThanEqualsToken | KindAmpersandEqualsToken | KindBarEqualsToken | KindBarBarEqualsToken | KindAmpersandAmpersandEqualsToken | KindQuestionQuestionEqualsToken | KindCaretEqualsToken - KeywordSyntaxKind = Kind // KindBreakKeyword | KindCaseKeyword | KindCatchKeyword | KindClassKeyword | KindConstKeyword | KindContinueKeyword | KindDebuggerKeyword | KindDefaultKeyword | KindDeleteKeyword | KindDoKeyword | KindElseKeyword | KindEnumKeyword | KindExportKeyword | KindExtendsKeyword | KindFalseKeyword | KindFinallyKeyword | KindForKeyword | KindFunctionKeyword | KindIfKeyword | KindImportKeyword | KindInKeyword | KindInstanceOfKeyword | KindNewKeyword | KindNullKeyword | KindReturnKeyword | KindSuperKeyword | KindSwitchKeyword | KindThisKeyword | KindThrowKeyword | KindTrueKeyword | KindTryKeyword | KindTypeOfKeyword | KindVarKeyword | KindVoidKeyword | KindWhileKeyword | KindWithKeyword | KindImplementsKeyword | KindInterfaceKeyword | KindLetKeyword | KindPackageKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindStaticKeyword | KindYieldKeyword | KindAbstractKeyword | KindAccessorKeyword | KindAsKeyword | KindAssertsKeyword | KindAssertKeyword | KindAnyKeyword | KindAsyncKeyword | KindAwaitKeyword | KindBooleanKeyword | KindConstructorKeyword | KindDeclareKeyword | KindGetKeyword | KindImmediateKeyword | KindInferKeyword | KindIntrinsicKeyword | KindIsKeyword | KindKeyOfKeyword | KindModuleKeyword | KindNamespaceKeyword | KindNeverKeyword | KindOutKeyword | KindReadonlyKeyword | KindRequireKeyword | KindNumberKeyword | KindObjectKeyword | KindSatisfiesKeyword | KindSetKeyword | KindStringKeyword | KindSymbolKeyword | KindTypeKeyword | KindUndefinedKeyword | KindUniqueKeyword | KindUnknownKeyword | KindUsingKeyword | KindFromKeyword | KindGlobalKeyword | KindBigIntKeyword | KindOverrideKeyword | KindOfKeyword | KindDeferKeyword + KeywordSyntaxKind = Kind // KindBreakKeyword | KindCaseKeyword | KindCatchKeyword | KindClassKeyword | KindConstKeyword | KindContinueKeyword | KindDebuggerKeyword | KindDefaultKeyword | KindDeleteKeyword | KindDoKeyword | KindElseKeyword | KindEnumKeyword | KindExportKeyword | KindExtendsKeyword | KindFalseKeyword | KindFinallyKeyword | KindForKeyword | KindFunctionKeyword | KindIfKeyword | KindImportKeyword | KindInKeyword | KindInstanceOfKeyword | KindNewKeyword | KindNullKeyword | KindReturnKeyword | KindSuperKeyword | KindSwitchKeyword | KindThisKeyword | KindThrowKeyword | KindTrueKeyword | KindTryKeyword | KindTypeOfKeyword | KindVarKeyword | KindVoidKeyword | KindWhileKeyword | KindWithKeyword | KindImplementsKeyword | KindInterfaceKeyword | KindLetKeyword | KindPackageKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindStaticKeyword | KindYieldKeyword | KindAbstractKeyword | KindAccessorKeyword | KindAsKeyword | KindAssertsKeyword | KindAssertKeyword | KindAnyKeyword | KindAsyncKeyword | KindAwaitKeyword | KindBooleanKeyword | KindConstructorKeyword | KindDeclareKeyword | KindGetKeyword | KindImmediateKeyword | KindInferKeyword | KindIntrinsicKeyword | KindIsKeyword | KindKeyOfKeyword | KindModuleKeyword | KindNamespaceKeyword | KindNeverKeyword | KindOutKeyword | KindReadonlyKeyword | KindRequireKeyword | KindNumberKeyword | KindObjectKeyword | KindSatisfiesKeyword | KindSetKeyword | KindStringKeyword | KindSymbolKeyword | KindTypeKeyword | KindUndefinedKeyword | KindUniqueKeyword | KindUnknownKeyword | KindUsingKeyword | KindFromKeyword | KindGlobalKeyword | KindBigIntKeyword | KindOverrideKeyword | KindOfKeyword | KindDeferKeyword | KindSourceKeyword ModifierSyntaxKind = Kind // KindAbstractKeyword | KindAccessorKeyword | KindAsyncKeyword | KindConstKeyword | KindDeclareKeyword | KindDefaultKeyword | KindExportKeyword | KindInKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindReadonlyKeyword | KindOutKeyword | KindOverrideKeyword | KindStaticKeyword KeywordTypeSyntaxKind = Kind // KindAnyKeyword | KindBigIntKeyword | KindBooleanKeyword | KindIntrinsicKeyword | KindNeverKeyword | KindNumberKeyword | KindObjectKeyword | KindStringKeyword | KindSymbolKeyword | KindUndefinedKeyword | KindUnknownKeyword | KindVoidKeyword KeywordExpressionSyntaxKind = Kind // KindNullKeyword | KindTrueKeyword | KindFalseKeyword | KindThisKeyword | KindSuperKeyword | KindImportKeyword - TokenSyntaxKind = Kind // KindUnknown | KindEndOfFile | KindSingleLineCommentTrivia | KindMultiLineCommentTrivia | KindNewLineTrivia | KindWhitespaceTrivia | KindConflictMarkerTrivia | KindNonTextFileMarkerTrivia | KindNumericLiteral | KindBigIntLiteral | KindStringLiteral | KindJsxText | KindJsxTextAllWhiteSpaces | KindRegularExpressionLiteral | KindNoSubstitutionTemplateLiteral | KindTemplateHead | KindTemplateMiddle | KindTemplateTail | KindOpenBraceToken | KindCloseBraceToken | KindOpenParenToken | KindCloseParenToken | KindOpenBracketToken | KindCloseBracketToken | KindDotToken | KindDotDotDotToken | KindSemicolonToken | KindCommaToken | KindQuestionDotToken | KindLessThanToken | KindLessThanSlashToken | KindGreaterThanToken | KindLessThanEqualsToken | KindGreaterThanEqualsToken | KindEqualsEqualsToken | KindExclamationEqualsToken | KindEqualsEqualsEqualsToken | KindExclamationEqualsEqualsToken | KindEqualsGreaterThanToken | KindPlusToken | KindMinusToken | KindAsteriskToken | KindAsteriskAsteriskToken | KindSlashToken | KindPercentToken | KindPlusPlusToken | KindMinusMinusToken | KindLessThanLessThanToken | KindGreaterThanGreaterThanToken | KindGreaterThanGreaterThanGreaterThanToken | KindAmpersandToken | KindBarToken | KindCaretToken | KindExclamationToken | KindTildeToken | KindAmpersandAmpersandToken | KindBarBarToken | KindQuestionToken | KindColonToken | KindAtToken | KindQuestionQuestionToken | KindBacktickToken | KindHashToken | KindEqualsToken | KindPlusEqualsToken | KindMinusEqualsToken | KindAsteriskEqualsToken | KindAsteriskAsteriskEqualsToken | KindSlashEqualsToken | KindPercentEqualsToken | KindLessThanLessThanEqualsToken | KindGreaterThanGreaterThanEqualsToken | KindGreaterThanGreaterThanGreaterThanEqualsToken | KindAmpersandEqualsToken | KindBarEqualsToken | KindBarBarEqualsToken | KindAmpersandAmpersandEqualsToken | KindQuestionQuestionEqualsToken | KindCaretEqualsToken | KindIdentifier | KindPrivateIdentifier | KindJSDocCommentTextToken | KindBreakKeyword | KindCaseKeyword | KindCatchKeyword | KindClassKeyword | KindConstKeyword | KindContinueKeyword | KindDebuggerKeyword | KindDefaultKeyword | KindDeleteKeyword | KindDoKeyword | KindElseKeyword | KindEnumKeyword | KindExportKeyword | KindExtendsKeyword | KindFalseKeyword | KindFinallyKeyword | KindForKeyword | KindFunctionKeyword | KindIfKeyword | KindImportKeyword | KindInKeyword | KindInstanceOfKeyword | KindNewKeyword | KindNullKeyword | KindReturnKeyword | KindSuperKeyword | KindSwitchKeyword | KindThisKeyword | KindThrowKeyword | KindTrueKeyword | KindTryKeyword | KindTypeOfKeyword | KindVarKeyword | KindVoidKeyword | KindWhileKeyword | KindWithKeyword | KindImplementsKeyword | KindInterfaceKeyword | KindLetKeyword | KindPackageKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindStaticKeyword | KindYieldKeyword | KindAbstractKeyword | KindAccessorKeyword | KindAsKeyword | KindAssertsKeyword | KindAssertKeyword | KindAnyKeyword | KindAsyncKeyword | KindAwaitKeyword | KindBooleanKeyword | KindConstructorKeyword | KindDeclareKeyword | KindGetKeyword | KindImmediateKeyword | KindInferKeyword | KindIntrinsicKeyword | KindIsKeyword | KindKeyOfKeyword | KindModuleKeyword | KindNamespaceKeyword | KindNeverKeyword | KindOutKeyword | KindReadonlyKeyword | KindRequireKeyword | KindNumberKeyword | KindObjectKeyword | KindSatisfiesKeyword | KindSetKeyword | KindStringKeyword | KindSymbolKeyword | KindTypeKeyword | KindUndefinedKeyword | KindUniqueKeyword | KindUnknownKeyword | KindUsingKeyword | KindFromKeyword | KindGlobalKeyword | KindBigIntKeyword | KindOverrideKeyword | KindOfKeyword | KindDeferKeyword + TokenSyntaxKind = Kind // KindUnknown | KindEndOfFile | KindSingleLineCommentTrivia | KindMultiLineCommentTrivia | KindNewLineTrivia | KindWhitespaceTrivia | KindConflictMarkerTrivia | KindNonTextFileMarkerTrivia | KindNumericLiteral | KindBigIntLiteral | KindStringLiteral | KindJsxText | KindJsxTextAllWhiteSpaces | KindRegularExpressionLiteral | KindNoSubstitutionTemplateLiteral | KindTemplateHead | KindTemplateMiddle | KindTemplateTail | KindOpenBraceToken | KindCloseBraceToken | KindOpenParenToken | KindCloseParenToken | KindOpenBracketToken | KindCloseBracketToken | KindDotToken | KindDotDotDotToken | KindSemicolonToken | KindCommaToken | KindQuestionDotToken | KindLessThanToken | KindLessThanSlashToken | KindGreaterThanToken | KindLessThanEqualsToken | KindGreaterThanEqualsToken | KindEqualsEqualsToken | KindExclamationEqualsToken | KindEqualsEqualsEqualsToken | KindExclamationEqualsEqualsToken | KindEqualsGreaterThanToken | KindPlusToken | KindMinusToken | KindAsteriskToken | KindAsteriskAsteriskToken | KindSlashToken | KindPercentToken | KindPlusPlusToken | KindMinusMinusToken | KindLessThanLessThanToken | KindGreaterThanGreaterThanToken | KindGreaterThanGreaterThanGreaterThanToken | KindAmpersandToken | KindBarToken | KindCaretToken | KindExclamationToken | KindTildeToken | KindAmpersandAmpersandToken | KindBarBarToken | KindQuestionToken | KindColonToken | KindAtToken | KindQuestionQuestionToken | KindBacktickToken | KindHashToken | KindEqualsToken | KindPlusEqualsToken | KindMinusEqualsToken | KindAsteriskEqualsToken | KindAsteriskAsteriskEqualsToken | KindSlashEqualsToken | KindPercentEqualsToken | KindLessThanLessThanEqualsToken | KindGreaterThanGreaterThanEqualsToken | KindGreaterThanGreaterThanGreaterThanEqualsToken | KindAmpersandEqualsToken | KindBarEqualsToken | KindBarBarEqualsToken | KindAmpersandAmpersandEqualsToken | KindQuestionQuestionEqualsToken | KindCaretEqualsToken | KindIdentifier | KindPrivateIdentifier | KindJSDocCommentTextToken | KindBreakKeyword | KindCaseKeyword | KindCatchKeyword | KindClassKeyword | KindConstKeyword | KindContinueKeyword | KindDebuggerKeyword | KindDefaultKeyword | KindDeleteKeyword | KindDoKeyword | KindElseKeyword | KindEnumKeyword | KindExportKeyword | KindExtendsKeyword | KindFalseKeyword | KindFinallyKeyword | KindForKeyword | KindFunctionKeyword | KindIfKeyword | KindImportKeyword | KindInKeyword | KindInstanceOfKeyword | KindNewKeyword | KindNullKeyword | KindReturnKeyword | KindSuperKeyword | KindSwitchKeyword | KindThisKeyword | KindThrowKeyword | KindTrueKeyword | KindTryKeyword | KindTypeOfKeyword | KindVarKeyword | KindVoidKeyword | KindWhileKeyword | KindWithKeyword | KindImplementsKeyword | KindInterfaceKeyword | KindLetKeyword | KindPackageKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindStaticKeyword | KindYieldKeyword | KindAbstractKeyword | KindAccessorKeyword | KindAsKeyword | KindAssertsKeyword | KindAssertKeyword | KindAnyKeyword | KindAsyncKeyword | KindAwaitKeyword | KindBooleanKeyword | KindConstructorKeyword | KindDeclareKeyword | KindGetKeyword | KindImmediateKeyword | KindInferKeyword | KindIntrinsicKeyword | KindIsKeyword | KindKeyOfKeyword | KindModuleKeyword | KindNamespaceKeyword | KindNeverKeyword | KindOutKeyword | KindReadonlyKeyword | KindRequireKeyword | KindNumberKeyword | KindObjectKeyword | KindSatisfiesKeyword | KindSetKeyword | KindStringKeyword | KindSymbolKeyword | KindTypeKeyword | KindUndefinedKeyword | KindUniqueKeyword | KindUnknownKeyword | KindUsingKeyword | KindFromKeyword | KindGlobalKeyword | KindBigIntKeyword | KindOverrideKeyword | KindOfKeyword | KindDeferKeyword | KindSourceKeyword JsxTokenSyntaxKind = Kind // KindLessThanSlashToken | KindEndOfFile | KindConflictMarkerTrivia | KindJsxText | KindJsxTextAllWhiteSpaces | KindOpenBraceToken | KindLessThanToken JSDocNodeSyntaxKind = Kind // KindJSDocTypeExpression | KindJSDocNameReference | KindJSDocAllType | KindJSDocNullableType | KindJSDocNonNullableType | KindJSDocOptionalType | KindJSDocVariadicType | KindJSDoc | KindJSDocText | KindJSDocTypeLiteral | KindJSDocSignature | KindJSDocLink | KindJSDocLinkCode | KindJSDocLinkPlain | KindJSDocUnknownTag | KindJSDocAugmentsTag | KindJSDocImplementsTag | KindJSDocDeprecatedTag | KindJSDocPublicTag | KindJSDocPrivateTag | KindJSDocProtectedTag | KindJSDocReadonlyTag | KindJSDocOverrideTag | KindJSDocCallbackTag | KindJSDocOverloadTag | KindJSDocParameterTag | KindJSDocReturnTag | KindJSDocThisTag | KindJSDocTypeTag | KindJSDocTemplateTag | KindJSDocTypedefTag | KindJSDocSeeTag | KindJSDocPropertyTag | KindJSDocThrowsTag | KindJSDocSatisfiesTag | KindJSDocImportTag - ImportPhaseModifierSyntaxKind = Kind // KindTypeKeyword | KindDeferKeyword + ImportPhaseModifierSyntaxKind = Kind // KindTypeKeyword | KindDeferKeyword | KindSourceKeyword PostfixUnaryOperator = Kind // KindPlusPlusToken | KindMinusMinusToken PrefixUnaryOperator = Kind // KindPlusToken | KindMinusToken | KindTildeToken | KindExclamationToken | KindPlusPlusToken | KindMinusMinusToken AssignmentOperator = Kind // KindEqualsToken | KindPlusEqualsToken | KindMinusEqualsToken | KindAsteriskAsteriskEqualsToken | KindAsteriskEqualsToken | KindSlashEqualsToken | KindPercentEqualsToken | KindAmpersandEqualsToken | KindBarEqualsToken | KindCaretEqualsToken | KindLessThanLessThanEqualsToken | KindGreaterThanGreaterThanGreaterThanEqualsToken | KindGreaterThanGreaterThanEqualsToken | KindBarBarEqualsToken | KindAmpersandAmpersandEqualsToken | KindQuestionQuestionEqualsToken diff --git a/tsc/internal/ast/kind_stringer_generated.go b/tsc/internal/ast/kind_stringer_generated.go index b80f1ba531982..9600c3d090453 100644 --- a/tsc/internal/ast/kind_stringer_generated.go +++ b/tsc/internal/ast/kind_stringer_generated.go @@ -175,196 +175,197 @@ func _() { _ = x[KindOverrideKeyword-164] _ = x[KindOfKeyword-165] _ = x[KindDeferKeyword-166] - _ = x[KindQualifiedName-167] - _ = x[KindComputedPropertyName-168] - _ = x[KindTypeParameter-169] - _ = x[KindParameter-170] - _ = x[KindDecorator-171] - _ = x[KindPropertySignature-172] - _ = x[KindPropertyDeclaration-173] - _ = x[KindMethodSignature-174] - _ = x[KindMethodDeclaration-175] - _ = x[KindClassStaticBlockDeclaration-176] - _ = x[KindConstructor-177] - _ = x[KindGetAccessor-178] - _ = x[KindSetAccessor-179] - _ = x[KindCallSignature-180] - _ = x[KindConstructSignature-181] - _ = x[KindIndexSignature-182] - _ = x[KindTypePredicate-183] - _ = x[KindTypeReference-184] - _ = x[KindFunctionType-185] - _ = x[KindConstructorType-186] - _ = x[KindTypeQuery-187] - _ = x[KindTypeLiteral-188] - _ = x[KindArrayType-189] - _ = x[KindTupleType-190] - _ = x[KindOptionalType-191] - _ = x[KindRestType-192] - _ = x[KindUnionType-193] - _ = x[KindIntersectionType-194] - _ = x[KindConditionalType-195] - _ = x[KindInferType-196] - _ = x[KindParenthesizedType-197] - _ = x[KindThisType-198] - _ = x[KindTypeOperator-199] - _ = x[KindIndexedAccessType-200] - _ = x[KindMappedType-201] - _ = x[KindLiteralType-202] - _ = x[KindNamedTupleMember-203] - _ = x[KindTemplateLiteralType-204] - _ = x[KindTemplateLiteralTypeSpan-205] - _ = x[KindImportType-206] - _ = x[KindObjectBindingPattern-207] - _ = x[KindArrayBindingPattern-208] - _ = x[KindBindingElement-209] - _ = x[KindArrayLiteralExpression-210] - _ = x[KindObjectLiteralExpression-211] - _ = x[KindPropertyAccessExpression-212] - _ = x[KindElementAccessExpression-213] - _ = x[KindCallExpression-214] - _ = x[KindNewExpression-215] - _ = x[KindTaggedTemplateExpression-216] - _ = x[KindTypeAssertionExpression-217] - _ = x[KindParenthesizedExpression-218] - _ = x[KindFunctionExpression-219] - _ = x[KindArrowFunction-220] - _ = x[KindDeleteExpression-221] - _ = x[KindTypeOfExpression-222] - _ = x[KindVoidExpression-223] - _ = x[KindAwaitExpression-224] - _ = x[KindPrefixUnaryExpression-225] - _ = x[KindPostfixUnaryExpression-226] - _ = x[KindBinaryExpression-227] - _ = x[KindConditionalExpression-228] - _ = x[KindTemplateExpression-229] - _ = x[KindYieldExpression-230] - _ = x[KindSpreadElement-231] - _ = x[KindClassExpression-232] - _ = x[KindOmittedExpression-233] - _ = x[KindExpressionWithTypeArguments-234] - _ = x[KindAsExpression-235] - _ = x[KindNonNullExpression-236] - _ = x[KindMetaProperty-237] - _ = x[KindSyntheticExpression-238] - _ = x[KindSatisfiesExpression-239] - _ = x[KindTemplateSpan-240] - _ = x[KindSemicolonClassElement-241] - _ = x[KindBlock-242] - _ = x[KindEmptyStatement-243] - _ = x[KindVariableStatement-244] - _ = x[KindExpressionStatement-245] - _ = x[KindIfStatement-246] - _ = x[KindDoStatement-247] - _ = x[KindWhileStatement-248] - _ = x[KindForStatement-249] - _ = x[KindForInStatement-250] - _ = x[KindForOfStatement-251] - _ = x[KindContinueStatement-252] - _ = x[KindBreakStatement-253] - _ = x[KindReturnStatement-254] - _ = x[KindWithStatement-255] - _ = x[KindSwitchStatement-256] - _ = x[KindLabeledStatement-257] - _ = x[KindThrowStatement-258] - _ = x[KindTryStatement-259] - _ = x[KindDebuggerStatement-260] - _ = x[KindVariableDeclaration-261] - _ = x[KindVariableDeclarationList-262] - _ = x[KindFunctionDeclaration-263] - _ = x[KindClassDeclaration-264] - _ = x[KindInterfaceDeclaration-265] - _ = x[KindTypeAliasDeclaration-266] - _ = x[KindEnumDeclaration-267] - _ = x[KindModuleDeclaration-268] - _ = x[KindModuleBlock-269] - _ = x[KindCaseBlock-270] - _ = x[KindNamespaceExportDeclaration-271] - _ = x[KindImportEqualsDeclaration-272] - _ = x[KindImportDeclaration-273] - _ = x[KindImportClause-274] - _ = x[KindNamespaceImport-275] - _ = x[KindNamedImports-276] - _ = x[KindImportSpecifier-277] - _ = x[KindExportAssignment-278] - _ = x[KindExportDeclaration-279] - _ = x[KindNamedExports-280] - _ = x[KindNamespaceExport-281] - _ = x[KindExportSpecifier-282] - _ = x[KindMissingDeclaration-283] - _ = x[KindExternalModuleReference-284] - _ = x[KindJsxElement-285] - _ = x[KindJsxSelfClosingElement-286] - _ = x[KindJsxOpeningElement-287] - _ = x[KindJsxClosingElement-288] - _ = x[KindJsxFragment-289] - _ = x[KindJsxOpeningFragment-290] - _ = x[KindJsxClosingFragment-291] - _ = x[KindJsxAttribute-292] - _ = x[KindJsxAttributes-293] - _ = x[KindJsxSpreadAttribute-294] - _ = x[KindJsxExpression-295] - _ = x[KindJsxNamespacedName-296] - _ = x[KindCaseClause-297] - _ = x[KindDefaultClause-298] - _ = x[KindHeritageClause-299] - _ = x[KindCatchClause-300] - _ = x[KindImportAttributes-301] - _ = x[KindImportAttribute-302] - _ = x[KindPropertyAssignment-303] - _ = x[KindShorthandPropertyAssignment-304] - _ = x[KindSpreadAssignment-305] - _ = x[KindEnumMember-306] - _ = x[KindSourceFile-307] - _ = x[KindJSDocTypeExpression-308] - _ = x[KindJSDocNameReference-309] - _ = x[KindJSDocAllType-310] - _ = x[KindJSDocNullableType-311] - _ = x[KindJSDocNonNullableType-312] - _ = x[KindJSDocOptionalType-313] - _ = x[KindJSDocVariadicType-314] - _ = x[KindJSDoc-315] - _ = x[KindJSDocText-316] - _ = x[KindJSDocTypeLiteral-317] - _ = x[KindJSDocSignature-318] - _ = x[KindJSDocLink-319] - _ = x[KindJSDocLinkCode-320] - _ = x[KindJSDocLinkPlain-321] - _ = x[KindJSDocUnknownTag-322] - _ = x[KindJSDocAugmentsTag-323] - _ = x[KindJSDocImplementsTag-324] - _ = x[KindJSDocDeprecatedTag-325] - _ = x[KindJSDocPublicTag-326] - _ = x[KindJSDocPrivateTag-327] - _ = x[KindJSDocProtectedTag-328] - _ = x[KindJSDocReadonlyTag-329] - _ = x[KindJSDocOverrideTag-330] - _ = x[KindJSDocCallbackTag-331] - _ = x[KindJSDocOverloadTag-332] - _ = x[KindJSDocParameterTag-333] - _ = x[KindJSDocReturnTag-334] - _ = x[KindJSDocThisTag-335] - _ = x[KindJSDocTypeTag-336] - _ = x[KindJSDocTemplateTag-337] - _ = x[KindJSDocTypedefTag-338] - _ = x[KindJSDocSeeTag-339] - _ = x[KindJSDocPropertyTag-340] - _ = x[KindJSDocThrowsTag-341] - _ = x[KindJSDocSatisfiesTag-342] - _ = x[KindJSDocImportTag-343] - _ = x[KindSyntaxList-344] - _ = x[KindJSTypeAliasDeclaration-345] - _ = x[KindJSImportDeclaration-346] - _ = x[KindNotEmittedStatement-347] - _ = x[KindPartiallyEmittedExpression-348] - _ = x[KindSyntheticReferenceExpression-349] - _ = x[KindNotEmittedTypeElement-350] - _ = x[KindCount-351] + _ = x[KindSourceKeyword-167] + _ = x[KindQualifiedName-168] + _ = x[KindComputedPropertyName-169] + _ = x[KindTypeParameter-170] + _ = x[KindParameter-171] + _ = x[KindDecorator-172] + _ = x[KindPropertySignature-173] + _ = x[KindPropertyDeclaration-174] + _ = x[KindMethodSignature-175] + _ = x[KindMethodDeclaration-176] + _ = x[KindClassStaticBlockDeclaration-177] + _ = x[KindConstructor-178] + _ = x[KindGetAccessor-179] + _ = x[KindSetAccessor-180] + _ = x[KindCallSignature-181] + _ = x[KindConstructSignature-182] + _ = x[KindIndexSignature-183] + _ = x[KindTypePredicate-184] + _ = x[KindTypeReference-185] + _ = x[KindFunctionType-186] + _ = x[KindConstructorType-187] + _ = x[KindTypeQuery-188] + _ = x[KindTypeLiteral-189] + _ = x[KindArrayType-190] + _ = x[KindTupleType-191] + _ = x[KindOptionalType-192] + _ = x[KindRestType-193] + _ = x[KindUnionType-194] + _ = x[KindIntersectionType-195] + _ = x[KindConditionalType-196] + _ = x[KindInferType-197] + _ = x[KindParenthesizedType-198] + _ = x[KindThisType-199] + _ = x[KindTypeOperator-200] + _ = x[KindIndexedAccessType-201] + _ = x[KindMappedType-202] + _ = x[KindLiteralType-203] + _ = x[KindNamedTupleMember-204] + _ = x[KindTemplateLiteralType-205] + _ = x[KindTemplateLiteralTypeSpan-206] + _ = x[KindImportType-207] + _ = x[KindObjectBindingPattern-208] + _ = x[KindArrayBindingPattern-209] + _ = x[KindBindingElement-210] + _ = x[KindArrayLiteralExpression-211] + _ = x[KindObjectLiteralExpression-212] + _ = x[KindPropertyAccessExpression-213] + _ = x[KindElementAccessExpression-214] + _ = x[KindCallExpression-215] + _ = x[KindNewExpression-216] + _ = x[KindTaggedTemplateExpression-217] + _ = x[KindTypeAssertionExpression-218] + _ = x[KindParenthesizedExpression-219] + _ = x[KindFunctionExpression-220] + _ = x[KindArrowFunction-221] + _ = x[KindDeleteExpression-222] + _ = x[KindTypeOfExpression-223] + _ = x[KindVoidExpression-224] + _ = x[KindAwaitExpression-225] + _ = x[KindPrefixUnaryExpression-226] + _ = x[KindPostfixUnaryExpression-227] + _ = x[KindBinaryExpression-228] + _ = x[KindConditionalExpression-229] + _ = x[KindTemplateExpression-230] + _ = x[KindYieldExpression-231] + _ = x[KindSpreadElement-232] + _ = x[KindClassExpression-233] + _ = x[KindOmittedExpression-234] + _ = x[KindExpressionWithTypeArguments-235] + _ = x[KindAsExpression-236] + _ = x[KindNonNullExpression-237] + _ = x[KindMetaProperty-238] + _ = x[KindSyntheticExpression-239] + _ = x[KindSatisfiesExpression-240] + _ = x[KindTemplateSpan-241] + _ = x[KindSemicolonClassElement-242] + _ = x[KindBlock-243] + _ = x[KindEmptyStatement-244] + _ = x[KindVariableStatement-245] + _ = x[KindExpressionStatement-246] + _ = x[KindIfStatement-247] + _ = x[KindDoStatement-248] + _ = x[KindWhileStatement-249] + _ = x[KindForStatement-250] + _ = x[KindForInStatement-251] + _ = x[KindForOfStatement-252] + _ = x[KindContinueStatement-253] + _ = x[KindBreakStatement-254] + _ = x[KindReturnStatement-255] + _ = x[KindWithStatement-256] + _ = x[KindSwitchStatement-257] + _ = x[KindLabeledStatement-258] + _ = x[KindThrowStatement-259] + _ = x[KindTryStatement-260] + _ = x[KindDebuggerStatement-261] + _ = x[KindVariableDeclaration-262] + _ = x[KindVariableDeclarationList-263] + _ = x[KindFunctionDeclaration-264] + _ = x[KindClassDeclaration-265] + _ = x[KindInterfaceDeclaration-266] + _ = x[KindTypeAliasDeclaration-267] + _ = x[KindEnumDeclaration-268] + _ = x[KindModuleDeclaration-269] + _ = x[KindModuleBlock-270] + _ = x[KindCaseBlock-271] + _ = x[KindNamespaceExportDeclaration-272] + _ = x[KindImportEqualsDeclaration-273] + _ = x[KindImportDeclaration-274] + _ = x[KindImportClause-275] + _ = x[KindNamespaceImport-276] + _ = x[KindNamedImports-277] + _ = x[KindImportSpecifier-278] + _ = x[KindExportAssignment-279] + _ = x[KindExportDeclaration-280] + _ = x[KindNamedExports-281] + _ = x[KindNamespaceExport-282] + _ = x[KindExportSpecifier-283] + _ = x[KindMissingDeclaration-284] + _ = x[KindExternalModuleReference-285] + _ = x[KindJsxElement-286] + _ = x[KindJsxSelfClosingElement-287] + _ = x[KindJsxOpeningElement-288] + _ = x[KindJsxClosingElement-289] + _ = x[KindJsxFragment-290] + _ = x[KindJsxOpeningFragment-291] + _ = x[KindJsxClosingFragment-292] + _ = x[KindJsxAttribute-293] + _ = x[KindJsxAttributes-294] + _ = x[KindJsxSpreadAttribute-295] + _ = x[KindJsxExpression-296] + _ = x[KindJsxNamespacedName-297] + _ = x[KindCaseClause-298] + _ = x[KindDefaultClause-299] + _ = x[KindHeritageClause-300] + _ = x[KindCatchClause-301] + _ = x[KindImportAttributes-302] + _ = x[KindImportAttribute-303] + _ = x[KindPropertyAssignment-304] + _ = x[KindShorthandPropertyAssignment-305] + _ = x[KindSpreadAssignment-306] + _ = x[KindEnumMember-307] + _ = x[KindSourceFile-308] + _ = x[KindJSDocTypeExpression-309] + _ = x[KindJSDocNameReference-310] + _ = x[KindJSDocAllType-311] + _ = x[KindJSDocNullableType-312] + _ = x[KindJSDocNonNullableType-313] + _ = x[KindJSDocOptionalType-314] + _ = x[KindJSDocVariadicType-315] + _ = x[KindJSDoc-316] + _ = x[KindJSDocText-317] + _ = x[KindJSDocTypeLiteral-318] + _ = x[KindJSDocSignature-319] + _ = x[KindJSDocLink-320] + _ = x[KindJSDocLinkCode-321] + _ = x[KindJSDocLinkPlain-322] + _ = x[KindJSDocUnknownTag-323] + _ = x[KindJSDocAugmentsTag-324] + _ = x[KindJSDocImplementsTag-325] + _ = x[KindJSDocDeprecatedTag-326] + _ = x[KindJSDocPublicTag-327] + _ = x[KindJSDocPrivateTag-328] + _ = x[KindJSDocProtectedTag-329] + _ = x[KindJSDocReadonlyTag-330] + _ = x[KindJSDocOverrideTag-331] + _ = x[KindJSDocCallbackTag-332] + _ = x[KindJSDocOverloadTag-333] + _ = x[KindJSDocParameterTag-334] + _ = x[KindJSDocReturnTag-335] + _ = x[KindJSDocThisTag-336] + _ = x[KindJSDocTypeTag-337] + _ = x[KindJSDocTemplateTag-338] + _ = x[KindJSDocTypedefTag-339] + _ = x[KindJSDocSeeTag-340] + _ = x[KindJSDocPropertyTag-341] + _ = x[KindJSDocThrowsTag-342] + _ = x[KindJSDocSatisfiesTag-343] + _ = x[KindJSDocImportTag-344] + _ = x[KindSyntaxList-345] + _ = x[KindJSTypeAliasDeclaration-346] + _ = x[KindJSImportDeclaration-347] + _ = x[KindNotEmittedStatement-348] + _ = x[KindPartiallyEmittedExpression-349] + _ = x[KindSyntheticReferenceExpression-350] + _ = x[KindNotEmittedTypeElement-351] + _ = x[KindCount-352] } -const _Kind_name = "KindUnknownKindEndOfFileKindSingleLineCommentTriviaKindMultiLineCommentTriviaKindNewLineTriviaKindWhitespaceTriviaKindConflictMarkerTriviaKindNonTextFileMarkerTriviaKindNumericLiteralKindBigIntLiteralKindStringLiteralKindJsxTextKindJsxTextAllWhiteSpacesKindRegularExpressionLiteralKindNoSubstitutionTemplateLiteralKindTemplateHeadKindTemplateMiddleKindTemplateTailKindOpenBraceTokenKindCloseBraceTokenKindOpenParenTokenKindCloseParenTokenKindOpenBracketTokenKindCloseBracketTokenKindDotTokenKindDotDotDotTokenKindSemicolonTokenKindCommaTokenKindQuestionDotTokenKindLessThanTokenKindLessThanSlashTokenKindGreaterThanTokenKindLessThanEqualsTokenKindGreaterThanEqualsTokenKindEqualsEqualsTokenKindExclamationEqualsTokenKindEqualsEqualsEqualsTokenKindExclamationEqualsEqualsTokenKindEqualsGreaterThanTokenKindPlusTokenKindMinusTokenKindAsteriskTokenKindAsteriskAsteriskTokenKindSlashTokenKindPercentTokenKindPlusPlusTokenKindMinusMinusTokenKindLessThanLessThanTokenKindGreaterThanGreaterThanTokenKindGreaterThanGreaterThanGreaterThanTokenKindAmpersandTokenKindBarTokenKindCaretTokenKindExclamationTokenKindTildeTokenKindAmpersandAmpersandTokenKindBarBarTokenKindQuestionTokenKindColonTokenKindAtTokenKindQuestionQuestionTokenKindBacktickTokenKindHashTokenKindEqualsTokenKindPlusEqualsTokenKindMinusEqualsTokenKindAsteriskEqualsTokenKindAsteriskAsteriskEqualsTokenKindSlashEqualsTokenKindPercentEqualsTokenKindLessThanLessThanEqualsTokenKindGreaterThanGreaterThanEqualsTokenKindGreaterThanGreaterThanGreaterThanEqualsTokenKindAmpersandEqualsTokenKindBarEqualsTokenKindBarBarEqualsTokenKindAmpersandAmpersandEqualsTokenKindQuestionQuestionEqualsTokenKindCaretEqualsTokenKindIdentifierKindPrivateIdentifierKindJSDocCommentTextTokenKindBreakKeywordKindCaseKeywordKindCatchKeywordKindClassKeywordKindConstKeywordKindContinueKeywordKindDebuggerKeywordKindDefaultKeywordKindDeleteKeywordKindDoKeywordKindElseKeywordKindEnumKeywordKindExportKeywordKindExtendsKeywordKindFalseKeywordKindFinallyKeywordKindForKeywordKindFunctionKeywordKindIfKeywordKindImportKeywordKindInKeywordKindInstanceOfKeywordKindNewKeywordKindNullKeywordKindReturnKeywordKindSuperKeywordKindSwitchKeywordKindThisKeywordKindThrowKeywordKindTrueKeywordKindTryKeywordKindTypeOfKeywordKindVarKeywordKindVoidKeywordKindWhileKeywordKindWithKeywordKindImplementsKeywordKindInterfaceKeywordKindLetKeywordKindPackageKeywordKindPrivateKeywordKindProtectedKeywordKindPublicKeywordKindStaticKeywordKindYieldKeywordKindAbstractKeywordKindAccessorKeywordKindAsKeywordKindAssertsKeywordKindAssertKeywordKindAnyKeywordKindAsyncKeywordKindAwaitKeywordKindBooleanKeywordKindConstructorKeywordKindDeclareKeywordKindGetKeywordKindImmediateKeywordKindInferKeywordKindIntrinsicKeywordKindIsKeywordKindKeyOfKeywordKindModuleKeywordKindNamespaceKeywordKindNeverKeywordKindOutKeywordKindReadonlyKeywordKindRequireKeywordKindNumberKeywordKindObjectKeywordKindSatisfiesKeywordKindSetKeywordKindStringKeywordKindSymbolKeywordKindTypeKeywordKindUndefinedKeywordKindUniqueKeywordKindUnknownKeywordKindUsingKeywordKindFromKeywordKindGlobalKeywordKindBigIntKeywordKindOverrideKeywordKindOfKeywordKindDeferKeywordKindQualifiedNameKindComputedPropertyNameKindTypeParameterKindParameterKindDecoratorKindPropertySignatureKindPropertyDeclarationKindMethodSignatureKindMethodDeclarationKindClassStaticBlockDeclarationKindConstructorKindGetAccessorKindSetAccessorKindCallSignatureKindConstructSignatureKindIndexSignatureKindTypePredicateKindTypeReferenceKindFunctionTypeKindConstructorTypeKindTypeQueryKindTypeLiteralKindArrayTypeKindTupleTypeKindOptionalTypeKindRestTypeKindUnionTypeKindIntersectionTypeKindConditionalTypeKindInferTypeKindParenthesizedTypeKindThisTypeKindTypeOperatorKindIndexedAccessTypeKindMappedTypeKindLiteralTypeKindNamedTupleMemberKindTemplateLiteralTypeKindTemplateLiteralTypeSpanKindImportTypeKindObjectBindingPatternKindArrayBindingPatternKindBindingElementKindArrayLiteralExpressionKindObjectLiteralExpressionKindPropertyAccessExpressionKindElementAccessExpressionKindCallExpressionKindNewExpressionKindTaggedTemplateExpressionKindTypeAssertionExpressionKindParenthesizedExpressionKindFunctionExpressionKindArrowFunctionKindDeleteExpressionKindTypeOfExpressionKindVoidExpressionKindAwaitExpressionKindPrefixUnaryExpressionKindPostfixUnaryExpressionKindBinaryExpressionKindConditionalExpressionKindTemplateExpressionKindYieldExpressionKindSpreadElementKindClassExpressionKindOmittedExpressionKindExpressionWithTypeArgumentsKindAsExpressionKindNonNullExpressionKindMetaPropertyKindSyntheticExpressionKindSatisfiesExpressionKindTemplateSpanKindSemicolonClassElementKindBlockKindEmptyStatementKindVariableStatementKindExpressionStatementKindIfStatementKindDoStatementKindWhileStatementKindForStatementKindForInStatementKindForOfStatementKindContinueStatementKindBreakStatementKindReturnStatementKindWithStatementKindSwitchStatementKindLabeledStatementKindThrowStatementKindTryStatementKindDebuggerStatementKindVariableDeclarationKindVariableDeclarationListKindFunctionDeclarationKindClassDeclarationKindInterfaceDeclarationKindTypeAliasDeclarationKindEnumDeclarationKindModuleDeclarationKindModuleBlockKindCaseBlockKindNamespaceExportDeclarationKindImportEqualsDeclarationKindImportDeclarationKindImportClauseKindNamespaceImportKindNamedImportsKindImportSpecifierKindExportAssignmentKindExportDeclarationKindNamedExportsKindNamespaceExportKindExportSpecifierKindMissingDeclarationKindExternalModuleReferenceKindJsxElementKindJsxSelfClosingElementKindJsxOpeningElementKindJsxClosingElementKindJsxFragmentKindJsxOpeningFragmentKindJsxClosingFragmentKindJsxAttributeKindJsxAttributesKindJsxSpreadAttributeKindJsxExpressionKindJsxNamespacedNameKindCaseClauseKindDefaultClauseKindHeritageClauseKindCatchClauseKindImportAttributesKindImportAttributeKindPropertyAssignmentKindShorthandPropertyAssignmentKindSpreadAssignmentKindEnumMemberKindSourceFileKindJSDocTypeExpressionKindJSDocNameReferenceKindJSDocAllTypeKindJSDocNullableTypeKindJSDocNonNullableTypeKindJSDocOptionalTypeKindJSDocVariadicTypeKindJSDocKindJSDocTextKindJSDocTypeLiteralKindJSDocSignatureKindJSDocLinkKindJSDocLinkCodeKindJSDocLinkPlainKindJSDocUnknownTagKindJSDocAugmentsTagKindJSDocImplementsTagKindJSDocDeprecatedTagKindJSDocPublicTagKindJSDocPrivateTagKindJSDocProtectedTagKindJSDocReadonlyTagKindJSDocOverrideTagKindJSDocCallbackTagKindJSDocOverloadTagKindJSDocParameterTagKindJSDocReturnTagKindJSDocThisTagKindJSDocTypeTagKindJSDocTemplateTagKindJSDocTypedefTagKindJSDocSeeTagKindJSDocPropertyTagKindJSDocThrowsTagKindJSDocSatisfiesTagKindJSDocImportTagKindSyntaxListKindJSTypeAliasDeclarationKindJSImportDeclarationKindNotEmittedStatementKindPartiallyEmittedExpressionKindSyntheticReferenceExpressionKindNotEmittedTypeElementKindCount" +const _Kind_name = "KindUnknownKindEndOfFileKindSingleLineCommentTriviaKindMultiLineCommentTriviaKindNewLineTriviaKindWhitespaceTriviaKindConflictMarkerTriviaKindNonTextFileMarkerTriviaKindNumericLiteralKindBigIntLiteralKindStringLiteralKindJsxTextKindJsxTextAllWhiteSpacesKindRegularExpressionLiteralKindNoSubstitutionTemplateLiteralKindTemplateHeadKindTemplateMiddleKindTemplateTailKindOpenBraceTokenKindCloseBraceTokenKindOpenParenTokenKindCloseParenTokenKindOpenBracketTokenKindCloseBracketTokenKindDotTokenKindDotDotDotTokenKindSemicolonTokenKindCommaTokenKindQuestionDotTokenKindLessThanTokenKindLessThanSlashTokenKindGreaterThanTokenKindLessThanEqualsTokenKindGreaterThanEqualsTokenKindEqualsEqualsTokenKindExclamationEqualsTokenKindEqualsEqualsEqualsTokenKindExclamationEqualsEqualsTokenKindEqualsGreaterThanTokenKindPlusTokenKindMinusTokenKindAsteriskTokenKindAsteriskAsteriskTokenKindSlashTokenKindPercentTokenKindPlusPlusTokenKindMinusMinusTokenKindLessThanLessThanTokenKindGreaterThanGreaterThanTokenKindGreaterThanGreaterThanGreaterThanTokenKindAmpersandTokenKindBarTokenKindCaretTokenKindExclamationTokenKindTildeTokenKindAmpersandAmpersandTokenKindBarBarTokenKindQuestionTokenKindColonTokenKindAtTokenKindQuestionQuestionTokenKindBacktickTokenKindHashTokenKindEqualsTokenKindPlusEqualsTokenKindMinusEqualsTokenKindAsteriskEqualsTokenKindAsteriskAsteriskEqualsTokenKindSlashEqualsTokenKindPercentEqualsTokenKindLessThanLessThanEqualsTokenKindGreaterThanGreaterThanEqualsTokenKindGreaterThanGreaterThanGreaterThanEqualsTokenKindAmpersandEqualsTokenKindBarEqualsTokenKindBarBarEqualsTokenKindAmpersandAmpersandEqualsTokenKindQuestionQuestionEqualsTokenKindCaretEqualsTokenKindIdentifierKindPrivateIdentifierKindJSDocCommentTextTokenKindBreakKeywordKindCaseKeywordKindCatchKeywordKindClassKeywordKindConstKeywordKindContinueKeywordKindDebuggerKeywordKindDefaultKeywordKindDeleteKeywordKindDoKeywordKindElseKeywordKindEnumKeywordKindExportKeywordKindExtendsKeywordKindFalseKeywordKindFinallyKeywordKindForKeywordKindFunctionKeywordKindIfKeywordKindImportKeywordKindInKeywordKindInstanceOfKeywordKindNewKeywordKindNullKeywordKindReturnKeywordKindSuperKeywordKindSwitchKeywordKindThisKeywordKindThrowKeywordKindTrueKeywordKindTryKeywordKindTypeOfKeywordKindVarKeywordKindVoidKeywordKindWhileKeywordKindWithKeywordKindImplementsKeywordKindInterfaceKeywordKindLetKeywordKindPackageKeywordKindPrivateKeywordKindProtectedKeywordKindPublicKeywordKindStaticKeywordKindYieldKeywordKindAbstractKeywordKindAccessorKeywordKindAsKeywordKindAssertsKeywordKindAssertKeywordKindAnyKeywordKindAsyncKeywordKindAwaitKeywordKindBooleanKeywordKindConstructorKeywordKindDeclareKeywordKindGetKeywordKindImmediateKeywordKindInferKeywordKindIntrinsicKeywordKindIsKeywordKindKeyOfKeywordKindModuleKeywordKindNamespaceKeywordKindNeverKeywordKindOutKeywordKindReadonlyKeywordKindRequireKeywordKindNumberKeywordKindObjectKeywordKindSatisfiesKeywordKindSetKeywordKindStringKeywordKindSymbolKeywordKindTypeKeywordKindUndefinedKeywordKindUniqueKeywordKindUnknownKeywordKindUsingKeywordKindFromKeywordKindGlobalKeywordKindBigIntKeywordKindOverrideKeywordKindOfKeywordKindDeferKeywordKindSourceKeywordKindQualifiedNameKindComputedPropertyNameKindTypeParameterKindParameterKindDecoratorKindPropertySignatureKindPropertyDeclarationKindMethodSignatureKindMethodDeclarationKindClassStaticBlockDeclarationKindConstructorKindGetAccessorKindSetAccessorKindCallSignatureKindConstructSignatureKindIndexSignatureKindTypePredicateKindTypeReferenceKindFunctionTypeKindConstructorTypeKindTypeQueryKindTypeLiteralKindArrayTypeKindTupleTypeKindOptionalTypeKindRestTypeKindUnionTypeKindIntersectionTypeKindConditionalTypeKindInferTypeKindParenthesizedTypeKindThisTypeKindTypeOperatorKindIndexedAccessTypeKindMappedTypeKindLiteralTypeKindNamedTupleMemberKindTemplateLiteralTypeKindTemplateLiteralTypeSpanKindImportTypeKindObjectBindingPatternKindArrayBindingPatternKindBindingElementKindArrayLiteralExpressionKindObjectLiteralExpressionKindPropertyAccessExpressionKindElementAccessExpressionKindCallExpressionKindNewExpressionKindTaggedTemplateExpressionKindTypeAssertionExpressionKindParenthesizedExpressionKindFunctionExpressionKindArrowFunctionKindDeleteExpressionKindTypeOfExpressionKindVoidExpressionKindAwaitExpressionKindPrefixUnaryExpressionKindPostfixUnaryExpressionKindBinaryExpressionKindConditionalExpressionKindTemplateExpressionKindYieldExpressionKindSpreadElementKindClassExpressionKindOmittedExpressionKindExpressionWithTypeArgumentsKindAsExpressionKindNonNullExpressionKindMetaPropertyKindSyntheticExpressionKindSatisfiesExpressionKindTemplateSpanKindSemicolonClassElementKindBlockKindEmptyStatementKindVariableStatementKindExpressionStatementKindIfStatementKindDoStatementKindWhileStatementKindForStatementKindForInStatementKindForOfStatementKindContinueStatementKindBreakStatementKindReturnStatementKindWithStatementKindSwitchStatementKindLabeledStatementKindThrowStatementKindTryStatementKindDebuggerStatementKindVariableDeclarationKindVariableDeclarationListKindFunctionDeclarationKindClassDeclarationKindInterfaceDeclarationKindTypeAliasDeclarationKindEnumDeclarationKindModuleDeclarationKindModuleBlockKindCaseBlockKindNamespaceExportDeclarationKindImportEqualsDeclarationKindImportDeclarationKindImportClauseKindNamespaceImportKindNamedImportsKindImportSpecifierKindExportAssignmentKindExportDeclarationKindNamedExportsKindNamespaceExportKindExportSpecifierKindMissingDeclarationKindExternalModuleReferenceKindJsxElementKindJsxSelfClosingElementKindJsxOpeningElementKindJsxClosingElementKindJsxFragmentKindJsxOpeningFragmentKindJsxClosingFragmentKindJsxAttributeKindJsxAttributesKindJsxSpreadAttributeKindJsxExpressionKindJsxNamespacedNameKindCaseClauseKindDefaultClauseKindHeritageClauseKindCatchClauseKindImportAttributesKindImportAttributeKindPropertyAssignmentKindShorthandPropertyAssignmentKindSpreadAssignmentKindEnumMemberKindSourceFileKindJSDocTypeExpressionKindJSDocNameReferenceKindJSDocAllTypeKindJSDocNullableTypeKindJSDocNonNullableTypeKindJSDocOptionalTypeKindJSDocVariadicTypeKindJSDocKindJSDocTextKindJSDocTypeLiteralKindJSDocSignatureKindJSDocLinkKindJSDocLinkCodeKindJSDocLinkPlainKindJSDocUnknownTagKindJSDocAugmentsTagKindJSDocImplementsTagKindJSDocDeprecatedTagKindJSDocPublicTagKindJSDocPrivateTagKindJSDocProtectedTagKindJSDocReadonlyTagKindJSDocOverrideTagKindJSDocCallbackTagKindJSDocOverloadTagKindJSDocParameterTagKindJSDocReturnTagKindJSDocThisTagKindJSDocTypeTagKindJSDocTemplateTagKindJSDocTypedefTagKindJSDocSeeTagKindJSDocPropertyTagKindJSDocThrowsTagKindJSDocSatisfiesTagKindJSDocImportTagKindSyntaxListKindJSTypeAliasDeclarationKindJSImportDeclarationKindNotEmittedStatementKindPartiallyEmittedExpressionKindSyntheticReferenceExpressionKindNotEmittedTypeElementKindCount" -var _Kind_index = [...]uint16{0, 11, 24, 51, 77, 94, 114, 138, 165, 183, 200, 217, 228, 253, 281, 314, 330, 348, 364, 382, 401, 419, 438, 458, 479, 491, 509, 527, 541, 561, 578, 600, 620, 643, 669, 690, 716, 743, 775, 801, 814, 828, 845, 870, 884, 900, 917, 936, 961, 992, 1034, 1052, 1064, 1078, 1098, 1112, 1139, 1154, 1171, 1185, 1196, 1221, 1238, 1251, 1266, 1285, 1305, 1328, 1359, 1379, 1401, 1432, 1469, 1517, 1541, 1559, 1580, 1613, 1644, 1664, 1678, 1699, 1724, 1740, 1755, 1771, 1787, 1803, 1822, 1841, 1859, 1876, 1889, 1904, 1919, 1936, 1954, 1970, 1988, 2002, 2021, 2034, 2051, 2064, 2085, 2099, 2114, 2131, 2147, 2164, 2179, 2195, 2210, 2224, 2241, 2255, 2270, 2286, 2301, 2322, 2342, 2356, 2374, 2392, 2412, 2429, 2446, 2462, 2481, 2500, 2513, 2531, 2548, 2562, 2578, 2594, 2612, 2634, 2652, 2666, 2686, 2702, 2722, 2735, 2751, 2768, 2788, 2804, 2818, 2837, 2855, 2872, 2889, 2909, 2923, 2940, 2957, 2972, 2992, 3009, 3027, 3043, 3058, 3075, 3092, 3111, 3124, 3140, 3157, 3181, 3198, 3211, 3224, 3245, 3268, 3287, 3308, 3339, 3354, 3369, 3384, 3401, 3423, 3441, 3458, 3475, 3491, 3510, 3523, 3538, 3551, 3564, 3580, 3592, 3605, 3625, 3644, 3657, 3678, 3690, 3706, 3727, 3741, 3756, 3776, 3799, 3826, 3840, 3864, 3887, 3905, 3931, 3958, 3986, 4013, 4031, 4048, 4076, 4103, 4130, 4152, 4169, 4189, 4209, 4227, 4246, 4271, 4297, 4317, 4342, 4364, 4383, 4400, 4419, 4440, 4471, 4487, 4508, 4524, 4547, 4570, 4586, 4611, 4620, 4638, 4659, 4682, 4697, 4712, 4730, 4746, 4764, 4782, 4803, 4821, 4840, 4857, 4876, 4896, 4914, 4930, 4951, 4974, 5001, 5024, 5044, 5068, 5092, 5111, 5132, 5147, 5160, 5190, 5217, 5238, 5254, 5273, 5289, 5308, 5328, 5349, 5365, 5384, 5403, 5425, 5452, 5466, 5491, 5512, 5533, 5548, 5570, 5592, 5608, 5625, 5647, 5664, 5685, 5699, 5716, 5734, 5749, 5769, 5788, 5810, 5841, 5861, 5875, 5889, 5912, 5934, 5950, 5971, 5995, 6016, 6037, 6046, 6059, 6079, 6097, 6110, 6127, 6145, 6164, 6184, 6206, 6228, 6246, 6265, 6286, 6306, 6326, 6346, 6366, 6387, 6405, 6421, 6437, 6457, 6476, 6491, 6511, 6529, 6550, 6568, 6582, 6608, 6631, 6654, 6684, 6716, 6741, 6750} +var _Kind_index = [...]uint16{0, 11, 24, 51, 77, 94, 114, 138, 165, 183, 200, 217, 228, 253, 281, 314, 330, 348, 364, 382, 401, 419, 438, 458, 479, 491, 509, 527, 541, 561, 578, 600, 620, 643, 669, 690, 716, 743, 775, 801, 814, 828, 845, 870, 884, 900, 917, 936, 961, 992, 1034, 1052, 1064, 1078, 1098, 1112, 1139, 1154, 1171, 1185, 1196, 1221, 1238, 1251, 1266, 1285, 1305, 1328, 1359, 1379, 1401, 1432, 1469, 1517, 1541, 1559, 1580, 1613, 1644, 1664, 1678, 1699, 1724, 1740, 1755, 1771, 1787, 1803, 1822, 1841, 1859, 1876, 1889, 1904, 1919, 1936, 1954, 1970, 1988, 2002, 2021, 2034, 2051, 2064, 2085, 2099, 2114, 2131, 2147, 2164, 2179, 2195, 2210, 2224, 2241, 2255, 2270, 2286, 2301, 2322, 2342, 2356, 2374, 2392, 2412, 2429, 2446, 2462, 2481, 2500, 2513, 2531, 2548, 2562, 2578, 2594, 2612, 2634, 2652, 2666, 2686, 2702, 2722, 2735, 2751, 2768, 2788, 2804, 2818, 2837, 2855, 2872, 2889, 2909, 2923, 2940, 2957, 2972, 2992, 3009, 3027, 3043, 3058, 3075, 3092, 3111, 3124, 3140, 3157, 3174, 3198, 3215, 3228, 3241, 3262, 3285, 3304, 3325, 3356, 3371, 3386, 3401, 3418, 3440, 3458, 3475, 3492, 3508, 3527, 3540, 3555, 3568, 3581, 3597, 3609, 3622, 3642, 3661, 3674, 3695, 3707, 3723, 3744, 3758, 3773, 3793, 3816, 3843, 3857, 3881, 3904, 3922, 3948, 3975, 4003, 4030, 4048, 4065, 4093, 4120, 4147, 4169, 4186, 4206, 4226, 4244, 4263, 4288, 4314, 4334, 4359, 4381, 4400, 4417, 4436, 4457, 4488, 4504, 4525, 4541, 4564, 4587, 4603, 4628, 4637, 4655, 4676, 4699, 4714, 4729, 4747, 4763, 4781, 4799, 4820, 4838, 4857, 4874, 4893, 4913, 4931, 4947, 4968, 4991, 5018, 5041, 5061, 5085, 5109, 5128, 5149, 5164, 5177, 5207, 5234, 5255, 5271, 5290, 5306, 5325, 5345, 5366, 5382, 5401, 5420, 5442, 5469, 5483, 5508, 5529, 5550, 5565, 5587, 5609, 5625, 5642, 5664, 5681, 5702, 5716, 5733, 5751, 5766, 5786, 5805, 5827, 5858, 5878, 5892, 5906, 5929, 5951, 5967, 5988, 6012, 6033, 6054, 6063, 6076, 6096, 6114, 6127, 6144, 6162, 6181, 6201, 6223, 6245, 6263, 6282, 6303, 6323, 6343, 6363, 6383, 6404, 6422, 6438, 6454, 6474, 6493, 6508, 6528, 6546, 6567, 6585, 6599, 6625, 6648, 6671, 6701, 6733, 6758, 6767} func (i Kind) String() string { idx := int(i) - 0 diff --git a/tsc/internal/ast/utilities.go b/tsc/internal/ast/utilities.go index 42058ea2c399f..3262132d8c0b1 100644 --- a/tsc/internal/ast/utilities.go +++ b/tsc/internal/ast/utilities.go @@ -1976,7 +1976,7 @@ func IsExpressionNode(node *Node) bool { KindJsxFragment, KindYieldExpression, KindAwaitExpression: return true case KindMetaProperty: - // `import.defer` in `import.defer(...)` is not an expression + // `import.` in `import.(...)` is not an expression return !IsImportCall(node.Parent) || node.Parent.Expression() != node case KindExpressionWithTypeArguments: return !IsHeritageClause(node.Parent) @@ -2114,7 +2114,27 @@ func IsImportCall(node *Node) bool { return false } e := node.Expression() - return e.Kind == KindImportKeyword || IsMetaProperty(e) && e.AsMetaProperty().KeywordToken == KindImportKeyword && e.Text() == "defer" + return e.Kind == KindImportKeyword || IsImportPhaseMetaProperty(e) +} + +func IsImportPhaseMetaProperty(node *Node) bool { + return IsImportDeferMetaProperty(node) || IsImportSourceMetaProperty(node) +} + +func IsImportDeferMetaProperty(node *Node) bool { + return isImportMetaProperty(node, "defer") +} + +func IsImportSourceMetaProperty(node *Node) bool { + return isImportMetaProperty(node, "source") +} + +func isImportMetaProperty(node *Node, name string) bool { + return IsMetaProperty(node) && node.AsMetaProperty().KeywordToken == KindImportKeyword && node.AsMetaProperty().Name().Text() == name +} + +func IsSourcePhaseImportCall(node *Node) bool { + return IsCallExpression(node) && IsImportSourceMetaProperty(node.Expression()) } func IsComputedNonLiteralName(name *Node) bool { diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 2a4ead5003a89..8f78f6cb5e3ef 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -562,6 +562,7 @@ type Program interface { GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, usageLocation *ast.StringLiteralLike) core.ResolutionMode GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ModuleKind GetResolvedModule(currentSourceFile ast.HasFileName, moduleReference string, mode core.ResolutionMode) *module.ResolvedModule + GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule] GetPackagesMap() map[string]bool GetSourceFileMetaData(path tspath.Path) ast.SourceFileMetaData @@ -654,6 +655,8 @@ type Checker struct { unresolvedSymbols map[string]*ast.Symbol errorTypes map[CacheHashKey]*Type moduleSymbols map[*ast.Node]*ast.Symbol + patternAmbientModuleSourceSymbols map[string]*ast.Symbol + resolvedModuleSourceSymbols map[tspath.Path]*ast.Symbol globalThisSymbol *ast.Symbol symbolTableAliasCache map[symbolTableID][]*ast.Symbol classExpressionNameTables map[ast.NodeId]ast.SymbolTable @@ -876,6 +879,7 @@ type Checker struct { getGlobalClassAccessorDecoratorTargetType func() *Type getGlobalClassAccessorDecoratorResultType func() *Type getGlobalClassFieldDecoratorContextType func() *Type + getGlobalWebAssemblyModuleType func() *Type syncIterationTypesResolver *IterationTypesResolver asyncIterationTypesResolver *IterationTypesResolver isPrimitiveOrObjectOrEmptyType func(*Type) bool @@ -1115,6 +1119,7 @@ func NewChecker(program Program, tracer *Tracer) (*Checker, *sync.Mutex) { c.getGlobalClassAccessorDecoratorTargetType = c.getGlobalTypeResolver("ClassAccessorDecoratorTarget", 2 /*arity*/, true /*reportErrors*/) c.getGlobalClassAccessorDecoratorResultType = c.getGlobalTypeResolver("ClassAccessorDecoratorResult", 2 /*arity*/, true /*reportErrors*/) c.getGlobalClassFieldDecoratorContextType = c.getGlobalTypeResolver("ClassFieldDecoratorContext", 2 /*arity*/, true /*reportErrors*/) + c.getGlobalWebAssemblyModuleType = core.Memoize(c.getGlobalWebAssemblyModuleTypeWorker) c.initializeClosures() c.initializeIterationResolvers() c.initializeChecker() @@ -8390,8 +8395,18 @@ func (c *Checker) checkImportCallExpression(node *ast.Node) *Type { } } // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal + isSourcePhaseImport := ast.IsSourcePhaseImportCall(node) + if isSourcePhaseImport { + resolvedModule, sourceType := c.getResolvedSourcePhaseImport(specifier) + if resolvedModule != nil { + return c.createPromiseReturnType(node, sourceType) + } + } moduleSymbol := c.resolveExternalModuleName(node, specifier, false /*ignoreErrors*/) if moduleSymbol != nil { + if isSourcePhaseImport { + return c.createPromiseReturnType(node, c.getSourcePhaseImportType(moduleSymbol)) + } esModuleSymbol := c.resolveExternalModuleSymbol(moduleSymbol, true /*dontResolveAlias*/) if esModuleSymbol != nil { syntheticType := c.getTypeWithSyntheticDefaultOnly(c.getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) @@ -10846,8 +10861,10 @@ func (c *Checker) checkMetaProperty(node *ast.Node) *Type { case ast.KindNewKeyword: return c.checkNewTargetMetaProperty(node) case ast.KindImportKeyword: - if node.Name().Text() == "defer" { - debug.Assert(!ast.IsCallExpression(node.Parent) || node.Parent.Expression() != node, "Trying to get the type of `import.defer` in `import.defer(...)`") + if ast.IsImportPhaseMetaProperty(node.AsNode()) { + if ast.IsCallExpression(node.Parent) { + debug.Assert(node.Parent.Expression() != node, "Trying to get the type of a phase import meta-property in its call") + } return c.errorType } return c.checkImportMetaProperty(node) @@ -14620,13 +14637,128 @@ func (c *Checker) getTypeOnlyDeclarationOfEntityName(name *ast.Node) *ast.Node { } func (c *Checker) getTargetOfImportClause(node *ast.Node) *ast.Symbol { - moduleSymbol := c.resolveExternalModuleName(node, getModuleSpecifierFromNode(node.Parent), false /*ignoreErrors*/) + specifier := getModuleSpecifierFromNode(node.Parent) + if node.AsImportClause().PhaseModifier == ast.KindSourceKeyword { + resolvedModule, sourceType := c.getResolvedSourcePhaseImport(specifier) + if resolvedModule != nil { + return c.getSourcePhaseImportTarget(specifier, nil /*moduleSymbol*/, resolvedModule.ResolvedFileName, sourceType) + } + } + moduleSymbol := c.resolveExternalModuleName(node, specifier, false /*ignoreErrors*/) if moduleSymbol != nil { + if node.AsImportClause().PhaseModifier == ast.KindSourceKeyword { + return c.getSourcePhaseImportTarget(specifier, moduleSymbol, "" /*resolvedFileName*/, c.getSourcePhaseImportType(moduleSymbol)) + } return c.getTargetOfModuleDefault(moduleSymbol, node, true /*dontResolveAlias*/) } return nil } +func (c *Checker) getSourcePhaseImportTarget(moduleSpecifier *ast.Node, moduleSymbol *ast.Symbol, resolvedFileName string, sourceType *Type) *ast.Symbol { + if moduleSymbol == nil { + path := tspath.ToPath(resolvedFileName, c.program.GetCurrentDirectory(), c.program.UseCaseSensitiveFileNames()) + sourceSymbol := c.resolvedModuleSourceSymbols[path] + if sourceSymbol != nil { + return sourceSymbol + } + sourceSymbol = c.createSourcePhaseImportTarget(nil /*moduleSymbol*/, sourceType) + if c.resolvedModuleSourceSymbols == nil { + c.resolvedModuleSourceSymbols = make(map[tspath.Path]*ast.Symbol) + } + c.resolvedModuleSourceSymbols[path] = sourceSymbol + return sourceSymbol + } + if c.isPatternAmbientModuleSymbol(moduleSymbol) { + key := c.getPatternAmbientModuleSourceKey(moduleSpecifier) + sourceSymbol := c.patternAmbientModuleSourceSymbols[key] + if sourceSymbol != nil { + return sourceSymbol + } + sourceSymbol = c.createSourcePhaseImportTarget(moduleSymbol, sourceType) + if c.patternAmbientModuleSourceSymbols == nil { + c.patternAmbientModuleSourceSymbols = make(map[string]*ast.Symbol) + } + c.patternAmbientModuleSourceSymbols[key] = sourceSymbol + return sourceSymbol + } + moduleLinks := c.moduleSymbolLinks.Get(moduleSymbol) + sourceSymbol := moduleLinks.sourcePhaseTarget + if sourceSymbol == nil { + sourceSymbol = c.createSourcePhaseImportTarget(moduleSymbol, sourceType) + moduleLinks.sourcePhaseTarget = sourceSymbol + } + return sourceSymbol +} + +func (c *Checker) isPatternAmbientModuleSymbol(moduleSymbol *ast.Symbol) bool { + for _, pattern := range c.patternAmbientModules { + if c.getMergedSymbol(pattern.Symbol) == moduleSymbol { + return true + } + } + return false +} + +func (c *Checker) getPatternAmbientModuleSourceKey(moduleSpecifier *ast.Node) string { + moduleReference := moduleSpecifier.Text() + if tspath.IsExternalModuleNameRelative(moduleReference) { + sourceFile := ast.GetSourceFileOfNode(moduleSpecifier) + path := tspath.GetNormalizedAbsolutePath(moduleReference, tspath.GetDirectoryPath(sourceFile.FileName())) + return tspath.GetCanonicalFileName(path, c.program.UseCaseSensitiveFileNames()) + } + return moduleReference +} + +func (c *Checker) createSourcePhaseImportTarget(moduleSymbol *ast.Symbol, sourceType *Type) *ast.Symbol { + sourceSymbol := c.newSymbol(ast.SymbolFlagsFunctionScopedVariable, "source") + sourceSymbol.Parent = moduleSymbol + c.valueSymbolLinks.Get(sourceSymbol).resolvedType = sourceType + return sourceSymbol +} + +func (c *Checker) getResolvedSourcePhaseImport(moduleSpecifier *ast.Node) (*module.ResolvedModule, *Type) { + if ast.IsStringLiteralLike(moduleSpecifier) { + sourceFile := ast.GetSourceFileOfNode(moduleSpecifier) + resolvedModule := c.program.GetResolvedModuleFromModuleSpecifier(sourceFile, moduleSpecifier) + if resolvedModule.IsResolved() { + if module.IsResolvedModuleForArbitraryExtension(resolvedModule, tspath.ExtensionWasm) { + if resolvedModule.ResolvedUsingTsExtension && tspath.IsDeclarationFileName(moduleSpecifier.Text()) { + return nil, nil + } + return resolvedModule, c.getGlobalWebAssemblyModuleType() + } + switch resolvedModule.Extension { + case tspath.ExtensionJs, tspath.ExtensionMjs, tspath.ExtensionCjs: + return resolvedModule, c.anyType + case tspath.ExtensionJsx: + if c.compilerOptions.Jsx != core.JsxEmitNone { + return resolvedModule, c.anyType + } + } + } + } + return nil, nil +} + +func (c *Checker) getSourcePhaseImportType(moduleSymbol *ast.Symbol) *Type { + if module.IsModuleForArbitraryExtension(moduleSymbol, tspath.ExtensionWasm) { + return c.getGlobalWebAssemblyModuleType() + } + return c.anyType +} + +func (c *Checker) getGlobalWebAssemblyModuleTypeWorker() *Type { + webAssemblySymbol := c.getGlobalSymbol("WebAssembly", ast.SymbolFlagsNamespace, nil /*diagnostic*/) + if webAssemblySymbol == nil { + return c.anyType + } + moduleTypeSymbol := c.getSymbol(c.getExportsOfSymbol(webAssemblySymbol), "Module", ast.SymbolFlagsType) + if moduleTypeSymbol == nil { + return c.anyType + } + return c.getDeclaredTypeOfSymbol(moduleTypeSymbol) +} + func (c *Checker) getTargetOfModuleDefault(moduleSymbol *ast.Symbol, node *ast.Node, dontResolveAlias bool) *ast.Symbol { file := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) specifier := c.getModuleSpecifierForImportOrExport(node) @@ -15298,7 +15430,13 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri mode = c.program.GetDefaultResolutionModeForFile(importingSourceFile) } - resolvedModule := c.program.GetResolvedModule(importingSourceFile, moduleReference, mode) + isSourcePhaseImport := contextSpecifier != nil && ast.IsStringLiteralLike(contextSpecifier) && module.GetImportPhaseForUsage(contextSpecifier) == module.ImportPhaseSource + var resolvedModule *module.ResolvedModule + if isSourcePhaseImport { + resolvedModule = c.program.GetResolvedModuleFromModuleSpecifier(importingSourceFile, contextSpecifier) + } else { + resolvedModule = c.program.GetResolvedModule(importingSourceFile, moduleReference, mode) + } var resolutionDiagnostic *diagnostics.Message if errorNode != nil && resolvedModule.IsResolved() { @@ -15319,15 +15457,15 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri if errorNode != nil { if resolvedModule.ResolvedUsingTsExtension && tspath.IsDeclarationFileName(moduleReference) { if ast.FindAncestor(location, ast.IsEmittableImport) != nil { - tsExtension := tspath.TryExtractTSExtension(moduleReference) - if tsExtension == "" { - panic("should be able to extract TS extension from string that passes IsDeclarationFileName") + if isSourcePhaseImport { + c.error(errorNode, diagnostics.A_declaration_file_cannot_be_imported_with_a_source_phase_import) + } else { + tsExtension := tspath.TryExtractTSExtension(moduleReference) + if tsExtension == "" { + panic("should be able to extract TS extension from string that passes IsDeclarationFileName") + } + c.error(errorNode, diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead, c.getSuggestedImportSource(moduleReference, tsExtension, mode)) } - c.error( - errorNode, - diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead, - c.getSuggestedImportSource(moduleReference, tsExtension, mode), - ) } } else if resolvedModule.ResolvedUsingTsExtension && !c.compilerOptions.AllowImportingTsExtensionsFrom(importingSourceFile.FileName()) { if ast.FindAncestor(location, ast.IsEmittableImport) != nil { @@ -31849,7 +31987,7 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy } return nil case ast.KindImportKeyword: - if ast.IsMetaProperty(node.Parent) && node.Parent.Text() == "defer" { + if ast.IsImportPhaseMetaProperty(node.Parent) { return nil } fallthrough diff --git a/tsc/internal/checker/grammarchecks.go b/tsc/internal/checker/grammarchecks.go index be8c0af0e6fcb..2a589b82d51fb 100644 --- a/tsc/internal/checker/grammarchecks.go +++ b/tsc/internal/checker/grammarchecks.go @@ -1822,13 +1822,13 @@ func (c *Checker) checkGrammarMetaProperty(node *ast.MetaProperty) bool { case ast.KindImportKeyword: if nameText != "meta" { isCallee := ast.IsCallExpression(node.Parent) && node.Parent.Expression() == node.AsNode() - if nameText == "defer" { + if ast.IsImportPhaseMetaProperty(node.AsNode()) { if !isCallee { return c.grammarErrorAtPos(node.AsNode(), node.AsNode().End(), 0, diagnostics.X_0_expected, "(") } } else { if isCallee { - return c.grammarErrorOnNode(nodeName, diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_or_defer, nameText) + return c.grammarErrorOnNode(nodeName, diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source, nameText) } return c.grammarErrorOnNode(nodeName, diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2, nameText, scanner.TokenToString(node.KeywordToken), "meta") } @@ -2113,9 +2113,25 @@ func (c *Checker) checkGrammarImportClause(node *ast.ImportClause) bool { if node.NamedBindings != nil && node.NamedBindings.Kind == ast.KindNamedImports { return c.grammarErrorOnNode(&node.Node, diagnostics.Named_imports_are_not_allowed_in_a_deferred_import) } - if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindPreserve { - return c.grammarErrorOnNode(&node.Node, diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve) + if c.moduleKind.SupportsDeferredImports() { + break + } + return c.grammarErrorOnNode(&node.Node, diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve) + case ast.KindSourceKeyword: + if node.NamedBindings != nil { + return c.grammarErrorOnNode(&node.Node, diagnostics.Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import) + } + if node.Name() == nil { + return c.grammarErrorOnNode(&node.Node, diagnostics.A_source_phase_import_must_specify_a_local_binding) + } + if c.moduleKind.SupportsSourcePhaseImports() { + moduleSpecifier := getModuleSpecifierFromNode(node.Parent) + if c.getEmitSyntaxForModuleSpecifierExpression(moduleSpecifier) == core.ModuleKindCommonJS { + return c.grammarErrorOnNode(&node.Node, diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls) + } + break } + return c.grammarErrorOnNode(&node.Node, diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve) } return false } @@ -2146,8 +2162,12 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool { return c.grammarErrorOnNode(node, getVerbatimModuleSyntaxErrorMessage(node)) } - if node.Expression().Kind == ast.KindMetaProperty { - if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindPreserve { + if ast.IsImportSourceMetaProperty(node.Expression()) { + if !c.moduleKind.SupportsSourcePhaseImports() { + return c.grammarErrorOnNode(node, diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve) + } + } else if ast.IsImportDeferMetaProperty(node.Expression()) { + if !c.moduleKind.SupportsDeferredImports() { return c.grammarErrorOnNode(node, diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve) } } else if c.moduleKind == core.ModuleKindES2015 { @@ -2155,6 +2175,9 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool { } nodeAsCall := node.AsCallExpression() + if ast.IsSourcePhaseImportCall(node) && nodeAsCall.QuestionDotToken != nil { + return c.grammarErrorOnNode(nodeAsCall.QuestionDotToken, diagnostics.Optional_chaining_cannot_be_used_with_import_source) + } if nodeAsCall.TypeArguments != nil { return c.grammarErrorOnNode(node, diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments) } diff --git a/tsc/internal/checker/types.go b/tsc/internal/checker/types.go index 2e8bacbd5df29..c284bc9ae9b6d 100644 --- a/tsc/internal/checker/types.go +++ b/tsc/internal/checker/types.go @@ -212,6 +212,7 @@ type AliasSymbolLinks struct { type ModuleSymbolLinks struct { resolvedExports ast.SymbolTable // Resolved exports of module or combined early- and late-bound static members of a class. typeOnlyExportStarMap map[string]*ast.Node // Set on a module symbol when some of its exports were resolved through a 'export type * from "mod"' declaration + sourcePhaseTarget *ast.Symbol exportsChecked bool } diff --git a/tsc/internal/compiler/contentmapper_test.go b/tsc/internal/compiler/contentmapper_test.go index 197914d47aaee..8e3856ebe72c0 100644 --- a/tsc/internal/compiler/contentmapper_test.go +++ b/tsc/internal/compiler/contentmapper_test.go @@ -91,6 +91,47 @@ func TestContentMapperVirtualExtensionSetsImpliedNodeFormat(t *testing.T) { assert.Equal(t, program.GetSourceFileMetaData(file.Path()).ImpliedNodeFormat, core.ResolutionModeESM) } +func TestEvaluationPhaseWasmUsesContentMapper(t *testing.T) { + t.Parallel() + if !bundled.Embedded { + t.Skip("bundled files are not embedded") + } + + fs := vfstest.FromMap(map[string]string{ + "/src/a.wasm": "\x00asm\x01\x00\x00\x00", + "/src/b.ts": `import { value } from "./a.wasm"; value;`, + }, false /*useCaseSensitiveFileNames*/) + fs = bundled.WrapFS(fs) + mapper := &contentmapper.Mapper{ + Definition: contentmapper.Definition{Package: "wasm", Extensions: []string{".wasm"}}, + Manifest: contentmapper.Manifest{Name: "wasm-mapper", Version: "1.0.0"}, + } + program := compiler.NewProgram(compiler.ProgramOptions{ + Config: &tsoptions.ParsedCommandLine{ + ParsedConfig: &tsoptions.ParsedOptions{ + FileNames: []string{"/src/b.ts"}, + CompilerOptions: &core.CompilerOptions{ + SkipLibCheck: core.TSTrue, + Module: core.ModuleKindESNext, + ModuleResolution: core.ModuleResolutionKindBundler, + }, + ContentMappers: []*contentmapper.Mapper{mapper}, + }, + }, + Host: compiler.NewCompilerHost("/src", fs, bundled.LibPath(), nil, nil, fakeContentMapperHost{ + transform: func(fileName string, content string) (contentmapper.Result, error) { + return contentmapper.Result{Text: "export const value = 1;", VirtualExtension: ".ts", Mappings: spanmap.New(nil)}, nil + }, + }), + SingleThreaded: core.TSTrue, + }) + + file := program.GetSourceFile("/src/a.wasm") + assert.Assert(t, file != nil) + assert.Equal(t, file.ContentMapper(), "wasm-mapper@1.0.0") + assert.Equal(t, len(collectContentMapperDiagnostics(program)), 0) +} + func collectContentMapperDiagnostics(program *compiler.Program) []*ast.Diagnostic { ctx := context.Background() return slices.Concat( diff --git a/tsc/internal/compiler/fileloader.go b/tsc/internal/compiler/fileloader.go index c89d06051692c..c4d4eeb97589c 100644 --- a/tsc/internal/compiler/fileloader.go +++ b/tsc/internal/compiler/fileloader.go @@ -868,13 +868,17 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) { } mode := getModeForUsageLocation(file.FileName(), meta, entry, optionsForFile) - resolvedModule, trace := p.resolver.ResolveModuleName(moduleName, fileName, mode, redirect) - resolutionsInFile[module.ModeAwareCacheKey{Name: moduleName, Mode: mode}] = resolvedModule + phase := module.GetImportPhaseForUsage(entry) + resolvedModule, trace := p.resolver.ResolveModuleNameWithPhase(moduleName, fileName, mode, phase, redirect) + resolutionsInFile[module.ModeAwareCacheKey{Name: moduleName, Mode: mode, Phase: phase}] = resolvedModule resolutionsTrace = append(resolutionsTrace, trace...) if !resolvedModule.IsResolved() { continue } + if phase == module.ImportPhaseSource && module.IsResolvedModuleForExtension(resolvedModule, tspath.ExtensionWasm) { + continue + } resolvedFileName := resolvedModule.ResolvedFileName isFromNodeModulesSearch := resolvedModule.IsExternalLibraryImport diff --git a/tsc/internal/compiler/program.go b/tsc/internal/compiler/program.go index 5b05af6697d04..878fd374731b7 100644 --- a/tsc/internal/compiler/program.go +++ b/tsc/internal/compiler/program.go @@ -439,7 +439,8 @@ func (p *Program) canReplaceFileInProgram(file1 *ast.SourceFile, file2 *ast.Sour file1.UsesUriStyleNodeCoreModules == file2.UsesUriStyleNodeCoreModules && slices.EqualFunc(file1.Imports(), file2.Imports(), func(n1 *ast.Node, n2 *ast.Node) bool { return equalModuleSpecifiers(n1, n2) && - p.GetModeForUsageLocation(file1, n1) == p.GetModeForUsageLocation(file2, n2) + p.GetModeForUsageLocation(file1, n1) == p.GetModeForUsageLocation(file2, n2) && + module.GetImportPhaseForUsage(n1) == module.GetImportPhaseForUsage(n2) }) && slices.EqualFunc(file1.ModuleAugmentations, file2.ModuleAugmentations, equalModuleAugmentationNames) && slices.Equal(file1.AmbientModuleNames, file2.AmbientModuleNames) && @@ -537,11 +538,15 @@ func (p *Program) extractUnresolvedImportsFromSourceFile(file *ast.SourceFile) [ resolvedModules := p.resolvedModules[file.Path()] for cacheKey, resolution := range resolvedModules { - resolved := resolution.IsResolved() - if (!resolved || !tspath.ExtensionIsOneOf(resolution.Extension, tspath.SupportedTSExtensionsWithJsonFlat)) && - !tspath.IsExternalModuleNameRelative(cacheKey.Name) { - unresolvedImports = append(unresolvedImports, cacheKey.Name) + if resolution.IsResolved() { + if cacheKey.Phase == module.ImportPhaseSource || tspath.ExtensionIsOneOf(resolution.Extension, tspath.SupportedTSExtensionsWithJsonFlat) { + continue + } + } + if tspath.IsExternalModuleNameRelative(cacheKey.Name) { + continue } + unresolvedImports = append(unresolvedImports, cacheKey.Name) } return unresolvedImports @@ -601,8 +606,12 @@ func (p *Program) GetTypeCheckerForFileExclusive(ctx context.Context, file *ast. } func (p *Program) GetResolvedModule(file ast.HasFileName, moduleReference string, mode core.ResolutionMode) *module.ResolvedModule { + return p.getResolvedModule(file, moduleReference, mode, module.ImportPhaseEvaluation) +} + +func (p *Program) getResolvedModule(file ast.HasFileName, moduleReference string, mode core.ResolutionMode, phase module.ImportPhase) *module.ResolvedModule { if resolutions, ok := p.resolvedModules[file.Path()]; ok { - if resolved, ok := resolutions[module.ModeAwareCacheKey{Name: moduleReference, Mode: mode}]; ok { + if resolved, ok := resolutions[module.ModeAwareCacheKey{Name: moduleReference, Mode: mode, Phase: phase}]; ok { return resolved } } @@ -614,7 +623,8 @@ func (p *Program) GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, mod panic("moduleSpecifier must be a StringLiteralLike") } mode := p.GetModeForUsageLocation(file, moduleSpecifier) - return p.GetResolvedModule(file, moduleSpecifier.Text(), mode) + phase := module.GetImportPhaseForUsage(moduleSpecifier) + return p.getResolvedModule(file, moduleSpecifier.Text(), mode, phase) } func (p *Program) GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule] { @@ -2159,7 +2169,7 @@ func (p *Program) collectPackageNames() *packageNamesInfo { continue } if resolvedModules, ok := p.resolvedModules[file.Path()]; ok { - key := module.ModeAwareCacheKey{Name: imp.Text(), Mode: p.GetModeForUsageLocation(file, imp)} + key := module.ModeAwareCacheKey{Name: imp.Text(), Mode: p.GetModeForUsageLocation(file, imp), Phase: module.GetImportPhaseForUsage(imp)} if resolvedModule, ok := resolvedModules[key]; ok && resolvedModule.IsResolved() { if !resolvedModule.IsExternalLibraryImport { continue @@ -2336,6 +2346,7 @@ var plainJSErrors = collections.NewSetFromItems( diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.Code(), diagnostics.A_set_accessor_cannot_have_rest_parameter.Code(), diagnostics.A_set_accessor_must_have_exactly_one_parameter.Code(), + diagnostics.A_source_phase_import_must_specify_a_local_binding.Code(), diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.Code(), diagnostics.An_export_declaration_cannot_have_modifiers.Code(), diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.Code(), @@ -2359,11 +2370,15 @@ var plainJSErrors = collections.NewSetFromItems( diagnostics.Jump_target_cannot_cross_function_boundary.Code(), diagnostics.Line_terminator_not_permitted_before_arrow.Code(), diagnostics.Modifiers_cannot_appear_here.Code(), + diagnostics.Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import.Code(), diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement.Code(), diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement.Code(), + diagnostics.Optional_chaining_cannot_be_used_with_import_source.Code(), diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies.Code(), diagnostics.Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression.Code(), diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier.Code(), + diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls.Code(), + diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve.Code(), diagnostics.Tagged_template_expressions_are_not_permitted_in_an_optional_chain.Code(), diagnostics.The_left_hand_side_of_a_for_of_statement_may_not_be_async.Code(), diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer.Code(), @@ -2372,6 +2387,7 @@ var plainJSErrors = collections.NewSetFromItems( diagnostics.Variable_declaration_list_cannot_be_empty.Code(), diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses.Code(), diagnostics.X_0_expected.Code(), + diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source.Code(), diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_2.Code(), diagnostics.X_0_list_cannot_be_empty.Code(), diagnostics.X_0_modifier_already_seen.Code(), diff --git a/tsc/internal/compiler/program_test.go b/tsc/internal/compiler/program_test.go index 77c3d23072913..1a0bd3520b525 100644 --- a/tsc/internal/compiler/program_test.go +++ b/tsc/internal/compiler/program_test.go @@ -305,6 +305,42 @@ func TestIncludeProcessorDiagnosticsWithMissingFileCasing(t *testing.T) { }()) } +func TestResolvedSourcePhaseImportsAreNotUnresolvedImports(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/node_modules/a/package.json": `{"name":"a","exports":"./a.wasm"}`, + "/repo/node_modules/a/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/node_modules/b/package.json": `{"name":"b","exports":"./b.wasm"}`, + "/repo/node_modules/b/b.d.wasm.ts": "export {};", + "/repo/node_modules/c/package.json": `{"name":"c","exports":"./c.js"}`, + "/repo/node_modules/c/c.js": "export {};", + "/repo/src/index.ts": `import source a from "a"; import source b from "b"; import source c from "c"; import source d from "missing";`, + }, true) + opts := core.CompilerOptions{ + Module: core.ModuleKindESNext, + ModuleResolution: core.ModuleResolutionKindBundler, + Target: core.ScriptTargetESNext, + NoLib: core.TSTrue, + } + program := compiler.NewProgram(compiler.ProgramOptions{ + Config: &tsoptions.ParsedCommandLine{ + ParsedConfig: &tsoptions.ParsedOptions{ + FileNames: []string{"/repo/src/index.ts"}, + CompilerOptions: &opts, + }, + }, + Host: compiler.NewCompilerHost("/repo", fs, bundled.LibPath(), nil /*extendedConfigCache*/, nil /*trace*/, nil /*contentMapperProject*/), + }) + + unresolvedImports := program.GetUnresolvedImports() + assert.Assert(t, !unresolvedImports.Has("a")) + assert.Assert(t, !unresolvedImports.Has("b")) + assert.Assert(t, !unresolvedImports.Has("c")) + assert.Assert(t, unresolvedImports.Has("missing")) + assert.Equal(t, unresolvedImports.Len(), 1) +} + func BenchmarkNewProgram(b *testing.B) { if !bundled.Embedded { // Without embedding, we'd need to read all of the lib files out from disk into the MapFS. diff --git a/tsc/internal/core/compileroptions.go b/tsc/internal/core/compileroptions.go index 55401a499f3a8..d01fc28fb6403 100644 --- a/tsc/internal/core/compileroptions.go +++ b/tsc/internal/core/compileroptions.go @@ -418,6 +418,14 @@ func (moduleKind ModuleKind) SupportsImportAttributes() bool { moduleKind == ModuleKindESNext } +func (moduleKind ModuleKind) SupportsDeferredImports() bool { + return moduleKind == ModuleKindESNext || moduleKind == ModuleKindPreserve +} + +func (moduleKind ModuleKind) SupportsSourcePhaseImports() bool { + return moduleKind == ModuleKindESNext || moduleKind == ModuleKindNodeNext || moduleKind == ModuleKindPreserve +} + type ResolutionMode = ModuleKind // ModuleKindNone | ModuleKindCommonJS | ModuleKindESNext const ( diff --git a/tsc/internal/diagnostics/diagnostics_generated.go b/tsc/internal/diagnostics/diagnostics_generated.go index 5c53bdcbb2641..9cdcbc151abaa 100644 --- a/tsc/internal/diagnostics/diagnostics_generated.go +++ b/tsc/internal/diagnostics/diagnostics_generated.go @@ -4414,6 +4414,20 @@ var The_invalid_diagnostic_directive_is_in_supplemental_output_0_returned_by_the var Diagnostic_directive_0_returned_by_the_content_mapper_has_an_invalid_unusedExpectDirectiveIndex = &Message{code: 100068, category: CategoryMessage, key: "Diagnostic_directive_0_returned_by_the_content_mapper_has_an_invalid_unusedExpectDirectiveIndex_100068", text: "Diagnostic directive {0} returned by the content mapper has an invalid 'unusedExpectDirectiveIndex'."} +var A_source_phase_import_must_specify_a_local_binding = &Message{code: 100069, category: CategoryError, key: "A_source_phase_import_must_specify_a_local_binding_100069", text: "A source phase import must specify a local binding."} + +var Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import = &Message{code: 100070, category: CategoryError, key: "Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import_100070", text: "Named and namespace imports are not allowed in a source phase import."} + +var Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve = &Message{code: 100071, category: CategoryError, key: "Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve_100071", text: "Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'."} + +var Optional_chaining_cannot_be_used_with_import_source = &Message{code: 100072, category: CategoryError, key: "Optional_chaining_cannot_be_used_with_import_source_100072", text: "Optional chaining cannot be used with 'import.source'."} + +var X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source = &Message{code: 100073, category: CategoryError, key: "_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source_100073", text: "'{0}' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'?"} + +var Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls = &Message{code: 100074, category: CategoryError, key: "Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls_100074", text: "Source phase imports are not allowed on statements that compile to CommonJS 'require' calls."} + +var A_declaration_file_cannot_be_imported_with_a_source_phase_import = &Message{code: 100075, category: CategoryError, key: "A_declaration_file_cannot_be_imported_with_a_source_phase_import_100075", text: "A declaration file cannot be imported with a source phase import."} + func keyToMessage(key Key) *Message { switch key { case "Unterminated_string_literal_1002": @@ -8828,6 +8842,20 @@ func keyToMessage(key Key) *Message { return The_invalid_diagnostic_directive_is_in_supplemental_output_0_returned_by_the_content_mapper case "Diagnostic_directive_0_returned_by_the_content_mapper_has_an_invalid_unusedExpectDirectiveIndex_100068": return Diagnostic_directive_0_returned_by_the_content_mapper_has_an_invalid_unusedExpectDirectiveIndex + case "A_source_phase_import_must_specify_a_local_binding_100069": + return A_source_phase_import_must_specify_a_local_binding + case "Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import_100070": + return Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import + case "Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve_100071": + return Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve + case "Optional_chaining_cannot_be_used_with_import_source_100072": + return Optional_chaining_cannot_be_used_with_import_source + case "_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source_100073": + return X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source + case "Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls_100074": + return Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls + case "A_declaration_file_cannot_be_imported_with_a_source_phase_import_100075": + return A_declaration_file_cannot_be_imported_with_a_source_phase_import default: return nil } diff --git a/tsc/internal/diagnostics/extraDiagnosticMessages.json b/tsc/internal/diagnostics/extraDiagnosticMessages.json index 3fe74485cb7fe..5edff7459091a 100644 --- a/tsc/internal/diagnostics/extraDiagnosticMessages.json +++ b/tsc/internal/diagnostics/extraDiagnosticMessages.json @@ -342,5 +342,33 @@ "Diagnostic directive {0} returned by the content mapper has an invalid 'unusedExpectDirectiveIndex'.": { "category": "Message", "code": 100068 + }, + "A source phase import must specify a local binding.": { + "category": "Error", + "code": 100069 + }, + "Named and namespace imports are not allowed in a source phase import.": { + "category": "Error", + "code": 100070 + }, + "Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.": { + "category": "Error", + "code": 100071 + }, + "Optional chaining cannot be used with 'import.source'.": { + "category": "Error", + "code": 100072 + }, + "'{0}' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'?": { + "category": "Error", + "code": 100073 + }, + "Source phase imports are not allowed on statements that compile to CommonJS 'require' calls.": { + "category": "Error", + "code": 100074 + }, + "A declaration file cannot be imported with a source phase import.": { + "category": "Error", + "code": 100075 } } diff --git a/tsc/internal/fourslash/tests/autoImport_sourcePhase_test.go b/tsc/internal/fourslash/tests/autoImport_sourcePhase_test.go new file mode 100644 index 0000000000000..d2517f3ee5459 --- /dev/null +++ b/tsc/internal/fourslash/tests/autoImport_sourcePhase_test.go @@ -0,0 +1,32 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestAutoImportDoesNotAddToSourcePhaseImport(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: esnext +// @Filename: /a.ts +const a = 0; +export default a; +export const b = 1; + +// @Filename: /b.ts +import source a from "./a"; +a; +b/**/` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.GoToMarker(t, "") + f.VerifyImportFixAtPosition(t, []string{ + `import source a from "./a"; +import { b } from "./a"; +a; +b`, + }, nil /*preferences*/) +} diff --git a/tsc/internal/fourslash/tests/completions_sourcePhase_test.go b/tsc/internal/fourslash/tests/completions_sourcePhase_test.go new file mode 100644 index 0000000000000..8e463e83f0bf2 --- /dev/null +++ b/tsc/internal/fourslash/tests/completions_sourcePhase_test.go @@ -0,0 +1,106 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + . "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestSourcePhaseImportPathCompletionsIncludeWasm(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: esnext +// @target: esnext + +// @filename: /a.wasm +wasm + +// @filename: /a.txt +text + +// @filename: /a.ts +export {}; + +// @filename: /b.ts +import source a from ".//*static*/"; +import.source(".//*dynamic*/"); +import(".//*evaluation*/");` + + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + + for _, marker := range []string{"static", "dynamic"} { + f.VerifyCompletions(t, marker, &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"a.wasm"}, + Excludes: []string{"a.txt"}, + }, + }) + } + + f.VerifyCompletions(t, "evaluation", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Excludes: []string{"a.wasm", "a.txt"}, + }, + }) +} + +func TestSourcePhaseImportPackageCompletionsUseRuntimeExportCondition(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: esnext +// @moduleResolution: bundler +// @target: esnext + +// @filename: /node_modules/pkg/package.json +{"name":"pkg","exports":{"./*":{"types":"./types/*.d.ts","default":"./wasm/*.wasm"}}} + +// @filename: /node_modules/pkg/types/a.d.ts +export {}; + +// @filename: /node_modules/pkg/wasm/b.wasm +wasm + +// @filename: /src/index.ts +import source a from "pkg//*source*/"; +import("pkg//*evaluation*/");` + + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + + f.VerifyCompletions(t, "source", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"b"}, + Excludes: []string{"a"}, + }, + }) + + f.VerifyCompletions(t, "evaluation", &fourslash.CompletionsExpectedList{ + IsIncomplete: false, + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ + CommitCharacters: &[]string{}, + EditRange: Ignored, + }, + Items: &fourslash.CompletionsExpectedItems{ + Includes: []fourslash.CompletionsExpectedItem{"a"}, + Excludes: []string{"b"}, + }, + }) +} diff --git a/tsc/internal/fourslash/tests/goToDefinition_sourcePhase_test.go b/tsc/internal/fourslash/tests/goToDefinition_sourcePhase_test.go new file mode 100644 index 0000000000000..25da4377c9c04 --- /dev/null +++ b/tsc/internal/fourslash/tests/goToDefinition_sourcePhase_test.go @@ -0,0 +1,30 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestGoToDefinition_sourcePhase(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @module: esnext +// @target: esnext + +// @filename: /a.wasm +wasm + +// @filename: /b.ts +import source b from "./a.wasm"; +[|/*bUse*/b|]; + +// @filename: /c.ts +import source c from "./a.wasm"; +[|/*cUse*/c|];` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineGoToDefinition(t, true, "bUse", "cUse") + f.VerifyBaselineFindAllReferences(t, "bUse", "cUse") +} diff --git a/tsc/internal/fourslash/tests/organizeImports_sourcePhase_test.go b/tsc/internal/fourslash/tests/organizeImports_sourcePhase_test.go new file mode 100644 index 0000000000000..4facd626065cd --- /dev/null +++ b/tsc/internal/fourslash/tests/organizeImports_sourcePhase_test.go @@ -0,0 +1,47 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/ls/lsutil" + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestOrganizeImports_sourcePhaseImportsAreNotCoalesced(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import source b from "lib"; +import source a from "lib"; +a; b;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyOrganizeImports( + t, + `import source a from "lib"; +import source b from "lib"; +a; b;`, + lsproto.CodeActionKindSourceSortImports, + &lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase}, + ) +} + +func TestOrganizeImports_sourceAndEvaluationPhaseImportsAreNotCoalesced(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `import { c } from "lib"; +import source b from "lib"; +import { a } from "lib"; +a; b; c;` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyOrganizeImports( + t, + `import source b from "lib"; +import { a, c } from "lib"; +a; b; c;`, + lsproto.CodeActionKindSourceSortImports, + &lsutil.UserPreferences{OrganizeImportsSort: lsutil.OrganizeImportsSortOrdinalIgnoreCase}, + ) +} diff --git a/tsc/internal/ls/autoimport/aliasresolver.go b/tsc/internal/ls/autoimport/aliasresolver.go index 52955e92c3d09..d919ab3acb907 100644 --- a/tsc/internal/ls/autoimport/aliasresolver.go +++ b/tsc/internal/ls/autoimport/aliasresolver.go @@ -114,12 +114,17 @@ func (r *aliasResolver) GetModeForUsageLocation(file ast.HasFileName, moduleSpec // GetResolvedModule implements checker.Program. func (r *aliasResolver) GetResolvedModule(currentSourceFile ast.HasFileName, moduleReference string, mode core.ResolutionMode) *module.ResolvedModule { + return r.getResolvedModule(currentSourceFile, moduleReference, mode, module.ImportPhaseEvaluation) +} + +func (r *aliasResolver) getResolvedModule(currentSourceFile ast.HasFileName, moduleReference string, mode core.ResolutionMode, phase module.ImportPhase) *module.ResolvedModule { cache, _ := r.resolvedModules.LoadOrStore(currentSourceFile.Path(), &collections.SyncMap[module.ModeAwareCacheKey, *module.ResolvedModule]{}) - if resolved, ok := cache.Load(module.ModeAwareCacheKey{Name: moduleReference, Mode: mode}); ok { + key := module.ModeAwareCacheKey{Name: moduleReference, Mode: mode, Phase: phase} + if resolved, ok := cache.Load(key); ok { return resolved } - resolved, _ := r.moduleResolver.ResolveModuleName(moduleReference, currentSourceFile.FileName(), mode, nil) - resolved, _ = cache.LoadOrStore(module.ModeAwareCacheKey{Name: moduleReference, Mode: mode}, resolved) + resolved, _ := r.moduleResolver.ResolveModuleNameWithPhase(moduleReference, currentSourceFile.FileName(), mode, phase, nil /*redirectedReference*/) + resolved, _ = cache.LoadOrStore(key, resolved) if !resolved.IsResolved() && !tspath.PathIsRelative(moduleReference) { r.onFailedAmbientModuleLookup(currentSourceFile, moduleReference) } @@ -211,7 +216,8 @@ func (r *aliasResolver) GetRedirectTargets(path tspath.Path) []string { // GetResolvedModuleFromModuleSpecifier implements checker.Program. func (r *aliasResolver) GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule { - panic("unimplemented") + phase := module.GetImportPhaseForUsage(moduleSpecifier) + return r.getResolvedModule(file, moduleSpecifier.Text(), r.GetModeForUsageLocation(file, moduleSpecifier), phase) } // GetSourceOfProjectReferenceIfOutputIncluded implements checker.Program. diff --git a/tsc/internal/ls/autoimport/fix.go b/tsc/internal/ls/autoimport/fix.go index a035f305eaf1d..b8f382866f462 100644 --- a/tsc/internal/ls/autoimport/fix.go +++ b/tsc/internal/ls/autoimport/fix.go @@ -749,6 +749,9 @@ func (v *View) tryAddToExistingImport( continue } importClause := importClauseNode.AsImportClause() + if importClause.PhaseModifier == ast.KindSourceKeyword { + continue + } namedBindings := importClause.NamedBindings // A type-only import may not have both a default and named imports, so the only way a name can diff --git a/tsc/internal/ls/definition.go b/tsc/internal/ls/definition.go index 29b48008199e1..68f06158fe96e 100644 --- a/tsc/internal/ls/definition.go +++ b/tsc/internal/ls/definition.go @@ -374,6 +374,13 @@ func getDeclarationsFromLocation(c *checker.Checker, node *ast.Node) []*ast.Node } if symbol.Flags&ast.SymbolFlagsAlias != 0 { if resolved, ok := c.ResolveAlias(symbol); ok { + if len(resolved.Declarations) == 0 { + for _, declaration := range symbol.Declarations { + if ast.IsImportClause(declaration) && declaration.AsImportClause().PhaseModifier == ast.KindSourceKeyword { + return symbol.Declarations + } + } + } symbol = resolved } } diff --git a/tsc/internal/ls/organizeimports.go b/tsc/internal/ls/organizeimports.go index f543d2c4b2f11..f35b91017247b 100644 --- a/tsc/internal/ls/organizeimports.go +++ b/tsc/internal/ls/organizeimports.go @@ -473,6 +473,21 @@ func coalesceImportsWorker( if categorized.importWithoutClause != nil { coalescedImports = append(coalescedImports, categorized.importWithoutClause) } + slices.SortFunc(categorized.sourcePhaseImports, func(a, b *ast.Statement) int { + aName := a.AsImportDeclaration().ImportClause.Name() + bName := b.AsImportDeclaration().ImportClause.Name() + if aName == nil && bName == nil { + return 0 + } + if aName == nil { + return 1 + } + if bName == nil { + return -1 + } + return comparer(aName.Text(), bName.Text()) + }) + coalescedImports = append(coalescedImports, categorized.sourcePhaseImports...) factory := ast.NewNodeFactory(ast.NodeFactoryHooks{}) @@ -634,6 +649,7 @@ func coalesceImportsWorker( type categorizedImports struct { importWithoutClause *ast.Statement + sourcePhaseImports []*ast.Statement typeOnlyImports importGroup regularImports importGroup } @@ -650,6 +666,7 @@ func (g importGroup) isEmpty() bool { func getCategorizedImports(importDecls []*ast.Statement) categorizedImports { var importWithoutClause *ast.Statement + var sourcePhaseImports []*ast.Statement var typeOnlyImports, regularImports importGroup for _, importDecl := range importDecls { @@ -661,6 +678,10 @@ func getCategorizedImports(importDecls []*ast.Statement) categorizedImports { } clause := importDecl.AsImportDeclaration().ImportClause.AsImportClause() + if clause.PhaseModifier == ast.KindSourceKeyword { + sourcePhaseImports = append(sourcePhaseImports, importDecl) + continue + } group := ®ularImports if clause.IsTypeOnly() { group = &typeOnlyImports @@ -685,6 +706,7 @@ func getCategorizedImports(importDecls []*ast.Statement) categorizedImports { return categorizedImports{ importWithoutClause: importWithoutClause, + sourcePhaseImports: sourcePhaseImports, typeOnlyImports: typeOnlyImports, regularImports: regularImports, } diff --git a/tsc/internal/ls/string_completions.go b/tsc/internal/ls/string_completions.go index e7580a55cdd00..ac0932f6c3795 100644 --- a/tsc/internal/ls/string_completions.go +++ b/tsc/internal/ls/string_completions.go @@ -675,7 +675,11 @@ func (l *LanguageService) getStringLiteralCompletionsFromModuleNamesWorker( scriptPath := file.Path() scriptDirectory := scriptPath.GetDirectoryPath() options := program.Options() + importPhase := module.GetImportPhaseForUsage(node) extensionOptions := l.getExtensionOptions(options, referenceKindModuleSpecifier, file, mode, checker) + if importPhase == module.ImportPhaseSource { + extensionOptions.extensionsToSearch = core.AppendIfUnique(extensionOptions.extensionsToSearch, tspath.ExtensionWasm) + } if isPathRelativeToScript(literalValue) || (options.Paths.Size() == 0 && (tspath.IsRootedDiskPath(literalValue) || tspath.IsUrl(literalValue))) { @@ -694,6 +698,7 @@ func (l *LanguageService) getStringLiteralCompletionsFromModuleNamesWorker( program, checker, extensionOptions, + importPhase, ) } } @@ -711,6 +716,7 @@ func (l *LanguageService) getCompletionEntriesForNonRelativeModules( program *compiler.Program, typeChecker *checker.Checker, extensionOptions *extensionOptions, + importPhase module.ImportPhase, ) []moduleCompletionNameAndKind { compilerOptions := program.Options() paths := compilerOptions.Paths @@ -731,7 +737,9 @@ func (l *LanguageService) getCompletionEntriesForNonRelativeModules( }) } - l.getCompletionEntriesFromTypings(program, scriptPath, fragmentDirectory, extensionOptions, result) + if importPhase == module.ImportPhaseEvaluation { + l.getCompletionEntriesFromTypings(program, scriptPath, fragmentDirectory, extensionOptions, result) + } if moduleResolutionUsesNodeModules(moduleResolution) { // If looking for a global package name, don't just include everything in `node_modules` because that includes dependencies' own dependencies. @@ -754,6 +762,11 @@ func (l *LanguageService) getCompletionEntriesForNonRelativeModules( resolvePackageJsonImports := compilerOptions.GetResolvePackageJsonImports() seenPackageScope := false conditions := module.GetConditions(compilerOptions, mode) + if importPhase == module.ImportPhaseSource { + conditions = slices.DeleteFunc(conditions, func(condition string) bool { + return condition == "types" + }) + } // Returns true if the search should stop. exportsOrImportsLookup := func(lookupTable *packagejson.ExportsOrImports, fragment string, baseDirectory string, isExports bool, isImports bool) bool { diff --git a/tsc/internal/module/cache.go b/tsc/internal/module/cache.go index 0de907f23212a..435d519c6becb 100644 --- a/tsc/internal/module/cache.go +++ b/tsc/internal/module/cache.go @@ -14,6 +14,7 @@ type moduleResolutionCacheKey struct { containingDirectory string moduleName string resolutionMode core.ResolutionMode + importPhase ImportPhase redirectConfigName string } diff --git a/tsc/internal/module/resolver.go b/tsc/internal/module/resolver.go index b408b7d4c027a..84b3566b7840c 100644 --- a/tsc/internal/module/resolver.go +++ b/tsc/internal/module/resolver.go @@ -79,6 +79,7 @@ type resolutionState struct { conditions []string extensions extensions compilerOptions *core.CompilerOptions + importPhase ImportPhase resolvePackageDirectoryOnly bool // state fields @@ -102,6 +103,7 @@ func newResolutionState( containingDirectory string, isTypeReferenceDirective bool, resolutionMode core.ResolutionMode, + importPhase ImportPhase, compilerOptions *core.CompilerOptions, redirectedReference ResolvedProjectReference, resolver *Resolver, @@ -111,6 +113,7 @@ func newResolutionState( name: name, containingDirectory: containingDirectory, compilerOptions: GetCompilerOptionsWithRedirect(compilerOptions, redirectedReference), + importPhase: importPhase, resolver: resolver, tracer: traceBuilder, } @@ -140,6 +143,11 @@ func newResolutionState( state.features = getNodeResolutionFeatures(compilerOptions) state.conditions = GetConditions(compilerOptions, resolutionMode) } + if importPhase == ImportPhaseSource { + state.conditions = slices.DeleteFunc(state.conditions, func(condition string) bool { + return condition == "types" + }) + } return state } @@ -259,7 +267,7 @@ func (r *Resolver) ResolveTypeReferenceDirective( traceBuilder.traceResolutionUsingProjectReference(redirectedReference) } - state := newResolutionState(typeReferenceDirectiveName, containingDirectory, true /*isTypeReferenceDirective*/, resolutionMode, compilerOptions, redirectedReference, r, traceBuilder) + state := newResolutionState(typeReferenceDirectiveName, containingDirectory, true /*isTypeReferenceDirective*/, resolutionMode, ImportPhaseEvaluation, compilerOptions, redirectedReference, r, traceBuilder) result := state.resolveTypeReferenceDirective(typeRoots, fromConfig, fromInferredTypesContainingFile) if traceBuilder != nil { @@ -272,6 +280,10 @@ func (r *Resolver) ResolveTypeReferenceDirective( } func (r *Resolver) ResolveModuleName(moduleName string, containingFile string, resolutionMode core.ResolutionMode, redirectedReference ResolvedProjectReference) (*ResolvedModule, []DiagAndArgs) { + return r.ResolveModuleNameWithPhase(moduleName, containingFile, resolutionMode, ImportPhaseEvaluation, redirectedReference) +} + +func (r *Resolver) ResolveModuleNameWithPhase(moduleName string, containingFile string, resolutionMode core.ResolutionMode, importPhase ImportPhase, redirectedReference ResolvedProjectReference) (*ResolvedModule, []DiagAndArgs) { containingDirectory := tspath.GetDirectoryPath(containingFile) traceBuilder := r.newTraceBuilder() @@ -279,6 +291,7 @@ func (r *Resolver) ResolveModuleName(moduleName string, containingFile string, r containingDirectory: containingDirectory, moduleName: moduleName, resolutionMode: resolutionMode, + importPhase: importPhase, redirectConfigName: getRedirectConfigName(redirectedReference), } @@ -308,7 +321,7 @@ func (r *Resolver) ResolveModuleName(moduleName string, containingFile string, r var result *ResolvedModule switch moduleResolution { case core.ModuleResolutionKindNode16, core.ModuleResolutionKindNodeNext, core.ModuleResolutionKindBundler: - state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, resolutionMode, compilerOptions, redirectedReference, r, traceBuilder) + state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, resolutionMode, importPhase, compilerOptions, redirectedReference, r, traceBuilder) result = state.resolveNodeLike() default: panic(fmt.Sprintf("Unexpected moduleResolution: %d", moduleResolution)) @@ -326,7 +339,12 @@ func (r *Resolver) ResolveModuleName(moduleName string, containingFile string, r } } - finalResult := r.tryResolveFromTypingsLocation(moduleName, containingDirectory, result, traceBuilder) + var finalResult *ResolvedModule + if importPhase == ImportPhaseSource { + finalResult = result + } else { + finalResult = r.tryResolveFromTypingsLocation(moduleName, containingDirectory, result, traceBuilder) + } r.moduleResolutionCache.Set(cacheKey, finalResult) return finalResult, traceBuilder.getTraces() @@ -335,7 +353,7 @@ func (r *Resolver) ResolveModuleName(moduleName string, containingFile string, r func (r *Resolver) ResolvePackageDirectory(moduleName string, containingFile string, resolutionMode core.ResolutionMode, redirectedReference ResolvedProjectReference) *ResolvedModule { compilerOptions := GetCompilerOptionsWithRedirect(r.compilerOptions, redirectedReference) containingDirectory := tspath.GetDirectoryPath(containingFile) - state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, resolutionMode, compilerOptions, redirectedReference, r, nil) + state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, resolutionMode, ImportPhaseEvaluation, compilerOptions, redirectedReference, r, nil /*traceBuilder*/) state.resolvePackageDirectoryOnly = true if result := state.loadModuleFromNearestNodeModulesDirectory(false /*typesScopeOnly*/); result != nil && result.path != "" { return state.createResolvedModuleHandlingSymlink(result) @@ -355,6 +373,7 @@ func (r *Resolver) tryResolveFromTypingsLocation(moduleName string, containingDi containingDirectory, false, /*isTypeReferenceDirective*/ core.ModuleKindNone, // resolutionMode, + ImportPhaseEvaluation, r.compilerOptions, nil, // redirectedReference, r, @@ -374,7 +393,7 @@ func (r *Resolver) tryResolveFromTypingsLocation(moduleName string, containingDi func (r *Resolver) resolveConfig(moduleName string, containingFile string) *ResolvedModule { containingDirectory := tspath.GetDirectoryPath(containingFile) - state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, core.ModuleKindCommonJS, r.compilerOptions, nil, r, nil) + state := newResolutionState(moduleName, containingDirectory, false /*isTypeReferenceDirective*/, core.ModuleKindCommonJS, ImportPhaseEvaluation, r.compilerOptions, nil /*redirectedReference*/, r, nil /*traceBuilder*/) state.isConfigLookup = true state.extensions = extensionsJson return state.resolveNodeLike() @@ -522,6 +541,9 @@ func (r *resolutionState) resolveNodeLike() *ResolvedModule { } } result := r.resolveNodeLikeWorker() + if r.importPhase == ImportPhaseSource { + return result + } if r.resolvedPackageDirectory && !r.isConfigLookup && r.features&NodeResolutionFeaturesExports != 0 && @@ -573,7 +595,7 @@ func (r *resolutionState) resolveNodeLikeWorker() *ResolvedModule { if resolved := r.loadModuleFromNearestNodeModulesDirectory(false /*typesScopeOnly*/); !resolved.shouldContinueSearching() { return r.createResolvedModuleHandlingSymlink(resolved) } - if r.extensions&extensionsDeclaration != 0 { + if r.importPhase == ImportPhaseEvaluation && r.extensions&extensionsDeclaration != 0 { if resolved := r.resolveFromTypeRoot(); !resolved.shouldContinueSearching() { return r.createResolvedModuleHandlingSymlink(resolved) } @@ -612,7 +634,11 @@ func (r *resolutionState) loadModuleFromSelfNameReference() *resolved { } else { subpath = "." } - // Maybe TODO: splitting extensions into two priorities should be unnecessary, except + // Source resolution prioritizes implementation files because declarations describe + // evaluation-phase exports. Evaluation resolution preserves the existing declaration-first + // behavior described below. + // + // Maybe TODO: splitting evaluation extensions into two priorities should be unnecessary, except // https://github.com/microsoft/TypeScript/issues/50762 makes the behavior different. // As long as that bug exists, we need to do two passes here in self-name loading // in order to be consistent with (non-self) library-name loading in @@ -628,8 +654,7 @@ func (r *resolutionState) loadModuleFromSelfNameReference() *resolved { if r.compilerOptions.GetAllowJS() && !strings.Contains(r.containingDirectory, "/node_modules/") { return r.loadModuleFromExports(scope, r.extensions, subpath) } - priorityExtensions := r.extensions & (extensionsTypeScript | extensionsDeclaration) - secondaryExtensions := r.extensions & ^(extensionsTypeScript | extensionsDeclaration) + priorityExtensions, secondaryExtensions := r.getExtensionPriority() if resolved := r.loadModuleFromExports(scope, priorityExtensions, subpath); !resolved.shouldContinueSearching() { return resolved } @@ -993,8 +1018,7 @@ func (r *resolutionState) loadModuleFromNearestNodeModulesDirectory(typesScopeOn // ii. DTS files in the @types package // 2. For each ancestor node_modules directory, try to find: // i. JS files in the implementation package - priorityExtensions := r.extensions & (extensionsTypeScript | extensionsDeclaration) - secondaryExtensions := r.extensions & ^(extensionsTypeScript | extensionsDeclaration) + priorityExtensions, secondaryExtensions := r.getExtensionPriority() // (1) if priorityExtensions != 0 { if r.tracer != nil { @@ -1044,7 +1068,7 @@ func (r *resolutionState) loadModuleFromImmediateNodeModulesDirectory(extensions } } - if extensions&extensionsDeclaration != 0 { + if r.importPhase == ImportPhaseEvaluation && extensions&extensionsDeclaration != 0 { nodeModulesAtTypes := tspath.CombinePaths(nodeModulesFolder, "@types") if !r.resolver.host.FS().DirectoryExists(nodeModulesAtTypes) { if r.tracer != nil { @@ -1142,7 +1166,7 @@ func (r *resolutionState) loadModuleFromSpecificNodeModulesDirectory(ext extensi // https://github.com/microsoft/TypeScript/pull/49327 return r.loadModuleFromExports(packageInfo, ext, tspath.CombinePaths(".", rest)) } - if rest != "" && packageInfo.Exists() { + if r.importPhase == ImportPhaseEvaluation && rest != "" && packageInfo.Exists() { versionPaths := packageInfo.Contents.GetVersionPaths(r.getTraceFunc()) if versionPaths.Exists() { if r.tracer != nil { @@ -1456,9 +1480,22 @@ func (r *resolutionState) loadModuleFromFileNoImplicitExtensions(extensions exte if r.tracer != nil { r.tracer.write(diagnostics.File_name_0_has_a_1_extension_stripping_it, candidate, extension) } + if r.importPhase == ImportPhaseSource && extensions&extensionsDeclaration != 0 { + if resolved := r.tryAddingExtensions(extensionless, extensions&^extensionsDeclaration, extension); !resolved.shouldContinueSearching() { + return resolved + } + extensions &= extensionsDeclaration + } return r.tryAddingExtensions(extensionless, extensions, extension) } +func (r *resolutionState) getExtensionPriority() (priority extensions, secondary extensions) { + if r.importPhase == ImportPhaseSource { + return r.extensions &^ extensionsDeclaration, r.extensions & extensionsDeclaration + } + return r.extensions & (extensionsTypeScript | extensionsDeclaration), r.extensions & ^(extensionsTypeScript | extensionsDeclaration) +} + func (r *resolutionState) tryAddingExtensions(extensionless string, extensions extensions, originalExtension string) *resolved { directory := tspath.GetDirectoryPath(extensionless) if directory != "" && !r.resolver.host.FS().DirectoryExists(directory) { @@ -1567,6 +1604,11 @@ func (r *resolutionState) tryAddingExtensions(extensionless string, extensions e } return continueSearching() default: + if r.importPhase == ImportPhaseSource && originalExtension == tspath.ExtensionWasm { + if resolved := r.tryExtension(tspath.ExtensionWasm, extensionless, false); !resolved.shouldContinueSearching() { + return resolved + } + } if slices.Contains(r.resolver.extraExtensions, originalExtension) { // A fully specified import of an extraExtension resolves directly to the file. if resolved := r.tryExtension(originalExtension, extensionless, false); !resolved.shouldContinueSearching() { @@ -1601,6 +1643,9 @@ func (r *resolutionState) tryFile(fileName string) (string, bool) { } ext := tspath.TryGetExtensionFromPath(fileName) + if ext == "" && r.importPhase == ImportPhaseSource && tspath.FileExtensionIs(fileName, tspath.ExtensionWasm) { + ext = tspath.ExtensionWasm + } fileNameNoExtension := tspath.RemoveExtension(fileName, ext) for _, suffix := range r.compilerOptions.ModuleSuffixes { path := fileNameNoExtension + suffix + ext @@ -1638,7 +1683,9 @@ func (r *resolutionState) loadNodeModuleFromDirectoryWorker(ext extensions, cand versionPaths packagejson.VersionPaths ) if packageInfo.Exists() { - versionPaths = packageInfo.Contents.GetVersionPaths(r.getTraceFunc()) + if r.importPhase == ImportPhaseEvaluation { + versionPaths = packageInfo.Contents.GetVersionPaths(r.getTraceFunc()) + } if tspath.ComparePaths(candidate, packageInfo.PackageDirectory, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: r.resolver.host.FS().UseCaseSensitiveFileNames()}) == 0 { if file, ok := r.getPackageFile(ext, packageInfo); ok { packageFile = file @@ -1760,7 +1807,7 @@ func (r *resolutionState) getPackageFile(extensions extensions, packageInfo *pac if r.isConfigLookup { return r.getPackageJSONPathField("tsconfig", &packageInfo.Contents.TSConfig, packageInfo.PackageDirectory) } - if extensions&extensionsDeclaration != 0 { + if r.importPhase == ImportPhaseEvaluation && extensions&extensionsDeclaration != 0 { if packageFile, ok := r.getPackageJSONPathField("typings", &packageInfo.Contents.Typings, packageInfo.PackageDirectory); ok { return packageFile, ok } diff --git a/tsc/internal/module/resolver_test.go b/tsc/internal/module/resolver_test.go index 1d75c85c4b47a..a9a0e2d264e31 100644 --- a/tsc/internal/module/resolver_test.go +++ b/tsc/internal/module/resolver_test.go @@ -8,6 +8,7 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/core" "github.com/microsoft/TypeScript/tsc/internal/module" + "github.com/microsoft/TypeScript/tsc/internal/tspath" "github.com/microsoft/TypeScript/tsc/internal/vfs" "github.com/microsoft/TypeScript/tsc/internal/vfs/vfstest" ) @@ -49,6 +50,286 @@ func TestResolveModuleNameTrailingSlash(t *testing.T) { } } +func TestResolveWasmModule(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/node_modules/pkg/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/node_modules/pkg/package.json": `{"name":"pkg","exports":"./a.wasm"}`, + "/repo/src/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/src/b.ts": "", + "/repo/src/c.wasm": "\x00asm\x01\x00\x00\x00", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("./a.wasm", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if !resolved.IsResolved() { + t.Fatal("Wasm module was not resolved") + } + if resolved.ResolvedFileName != "/repo/src/a.wasm" { + t.Fatalf("resolved file name = %q, want %q", resolved.ResolvedFileName, "/repo/src/a.wasm") + } + if resolved.Extension != tspath.ExtensionWasm { + t.Fatalf("resolved extension = %q, want %q", resolved.Extension, tspath.ExtensionWasm) + } + + resolved, _ = resolver.ResolveModuleName("./a.wasm", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("Wasm module resolved in the evaluation phase to %q", resolved.ResolvedFileName) + } + + resolved, _ = resolver.ResolveModuleName("./c.wasm", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("Wasm module resolved in the evaluation phase to %q", resolved.ResolvedFileName) + } + resolved, _ = resolver.ResolveModuleNameWithPhase("./c.wasm", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if !resolved.IsResolved() { + t.Fatal("Wasm module was not resolved after an evaluation-phase miss") + } + + resolved, _ = resolver.ResolveModuleNameWithPhase("pkg", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if !resolved.IsResolved() { + t.Fatal("package Wasm module was not resolved") + } + if resolved.ResolvedFileName != "/repo/node_modules/pkg/a.wasm" { + t.Fatalf("resolved package file name = %q, want %q", resolved.ResolvedFileName, "/repo/node_modules/pkg/a.wasm") + } + + resolved, _ = resolver.ResolveModuleName("pkg", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("package Wasm module resolved in the evaluation phase to %q", resolved.ResolvedFileName) + } +} + +func TestSourcePhaseWasmPrefersRuntimeFile(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/src/a.d.wasm.ts": "export const value: number;", + "/repo/src/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("./a.wasm", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/src/a.wasm") + + resolved, _ = resolver.ResolveModuleName("./a.wasm", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/src/a.d.wasm.ts") +} + +func TestSourcePhasePrefersJavaScriptOverDeclarationFile(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/src/a.d.ts": "export const value: number;", + "/repo/src/a.js": "export const value = 1;", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("./a.js", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/src/a.js") + + resolved, _ = resolver.ResolveModuleName("./a.js", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/src/a.d.ts") +} + +func assertResolvedFileName(t *testing.T, resolved *module.ResolvedModule, expected string) { + t.Helper() + if !resolved.IsResolved() { + t.Fatalf("module was not resolved, want %q", expected) + } + if resolved.ResolvedFileName != expected { + t.Fatalf("resolved file name = %q, want %q", resolved.ResolvedFileName, expected) + } +} + +func TestSourcePhasePackageResolutionUsesRuntimeTarget(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/node_modules/exports/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/node_modules/exports/index.d.ts": "export {};", + "/repo/node_modules/exports/package.json": `{"name":"exports","exports":{"types":"./index.d.ts","default":"./a.wasm"}}`, + "/repo/node_modules/main/a.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/node_modules/main/index.d.ts": "export {};", + "/repo/node_modules/main/package.json": `{"name":"main","types":"./index.d.ts","main":"./a.wasm"}`, + "/repo/node_modules/js/index.d.ts": "export {};", + "/repo/node_modules/js/index.js": "export {};", + "/repo/node_modules/js/package.json": `{"name":"js","types":"./index.d.ts","main":"./index.js"}`, + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + for _, packageName := range []string{"exports", "main"} { + resolved, _ := resolver.ResolveModuleNameWithPhase(packageName, "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + expected := "/repo/node_modules/" + packageName + "/a.wasm" + if resolved.ResolvedFileName != expected { + t.Errorf("source phase %q resolved to %q, want %q", packageName, resolved.ResolvedFileName, expected) + } + if resolved.AlternateResult != "" { + t.Errorf("source phase %q has alternate type resolution %q", packageName, resolved.AlternateResult) + } + + resolved, _ = resolver.ResolveModuleName(packageName, "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + expected = "/repo/node_modules/" + packageName + "/index.d.ts" + if resolved.ResolvedFileName != expected { + t.Errorf("evaluation phase %q resolved to %q, want %q", packageName, resolved.ResolvedFileName, expected) + } + } + + resolved, _ := resolver.ResolveModuleNameWithPhase("js", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/node_modules/js/index.js") + resolved, _ = resolver.ResolveModuleName("js", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/node_modules/js/index.d.ts") +} + +func TestSourcePhaseDoesNotResolveFromTypesPackage(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/node_modules/@types/a/index.d.ts": "export {};", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("a", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("source phase resolved through @types to %q", resolved.ResolvedFileName) + } + + resolved, _ = resolver.ResolveModuleName("a", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/node_modules/@types/a/index.d.ts") +} + +func TestSourcePhaseDoesNotResolveFromTypeRoots(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/types/a/index.d.ts": "export {};", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + TypeRoots: []string{"/repo/types"}, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("a", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("source phase resolved through typeRoots to %q", resolved.ResolvedFileName) + } + + resolved, _ = resolver.ResolveModuleName("a", "/repo/src/b.ts", core.ModuleKindESNext, nil /*redirectedReference*/) + assertResolvedFileName(t, resolved, "/repo/types/a/index.d.ts") +} + +func TestResolveWasmModuleWithModuleSuffix(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/src/a.native.wasm": "\x00asm\x01\x00\x00\x00", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + ModuleSuffixes: []string{".native"}, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("./a.wasm", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if !resolved.IsResolved() { + t.Fatal("Wasm module was not resolved") + } + if resolved.ResolvedFileName != "/repo/src/a.native.wasm" { + t.Fatalf("resolved file name = %q, want %q", resolved.ResolvedFileName, "/repo/src/a.native.wasm") + } +} + +func TestSourcePhaseDoesNotResolveUnknownPhysicalModuleTypes(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/src/a.txt": "text", + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "", "", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("./a.txt", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if resolved.IsResolved() { + t.Fatalf("Unknown physical module type resolved to %q", resolved.ResolvedFileName) + } +} + +func TestResolveWasmModuleDeclarationSidecarIgnoresGlobalTypings(t *testing.T) { + t.Parallel() + + fs := vfstest.FromMap(map[string]string{ + "/repo/cache/node_modules/pkg/index.d.ts": `export {};`, + "/repo/node_modules/pkg/a.d.wasm.ts": `export {};`, + "/repo/node_modules/pkg/package.json": `{"name":"pkg","exports":"./a.wasm"}`, + "/repo/src/b.ts": "", + }, true) + host := &resolutionHostStub{fs: fs, cwd: "/repo"} + opts := &core.CompilerOptions{ + ModuleResolution: core.ModuleResolutionKindBundler, + Module: core.ModuleKindESNext, + Target: core.ScriptTargetESNext, + } + resolver := module.NewResolver(host, opts, "/repo/cache", "project", nil) + + resolved, _ := resolver.ResolveModuleNameWithPhase("pkg", "/repo/src/b.ts", core.ModuleKindESNext, module.ImportPhaseSource, nil /*redirectedReference*/) + if !resolved.IsResolved() { + t.Fatal("Wasm module declaration sidecar was not resolved") + } + if resolved.ResolvedFileName != "/repo/node_modules/pkg/a.d.wasm.ts" { + t.Fatalf("resolved file name = %q, want %q", resolved.ResolvedFileName, "/repo/node_modules/pkg/a.d.wasm.ts") + } +} + // blockingFS wraps a vfs.FS and forces FileExists calls for `targetPath` to // block on `gate` until released. Each caller sends on `arrived` when it // reaches the gate. This is used to deterministically reproduce the diff --git a/tsc/internal/module/types.go b/tsc/internal/module/types.go index 72e2573adf3fe..7bdf09e0b9ce3 100644 --- a/tsc/internal/module/types.go +++ b/tsc/internal/module/types.go @@ -17,10 +17,18 @@ type ResolutionHost interface { } type ModeAwareCacheKey struct { - Name string - Mode core.ResolutionMode + Name string + Mode core.ResolutionMode + Phase ImportPhase } +type ImportPhase int32 + +const ( + ImportPhaseEvaluation ImportPhase = iota + ImportPhaseSource +) + type ResolvedProjectReference interface { ConfigName() string CompilerOptions() *core.CompilerOptions diff --git a/tsc/internal/module/util.go b/tsc/internal/module/util.go index 5e06fd6c421e3..a2ff1257d440e 100644 --- a/tsc/internal/module/util.go +++ b/tsc/internal/module/util.go @@ -1,6 +1,7 @@ package module import ( + "slices" "strings" "github.com/microsoft/TypeScript/tsc/internal/ast" @@ -14,6 +15,48 @@ var typeScriptVersion = semver.MustParse(core.Version()) const InferredTypesContainingFile = "__inferred type names__.ts" +func GetImportPhaseForUsage(usage *ast.StringLiteralLike) ImportPhase { + parent := usage.Parent + if parent == nil { + return ImportPhaseEvaluation + } + if ast.IsImportDeclaration(parent) { + importClause := parent.AsImportDeclaration().ImportClause + if importClause != nil && importClause.AsImportClause().PhaseModifier == ast.KindSourceKeyword { + return ImportPhaseSource + } + } else if ast.IsSourcePhaseImportCall(parent) { + arguments := parent.Arguments() + if len(arguments) > 0 && arguments[0] == usage { + return ImportPhaseSource + } + } + return ImportPhaseEvaluation +} + +func IsModuleForArbitraryExtension(moduleSymbol *ast.Symbol, extension string) bool { + file := ast.GetSourceFileOfModule(moduleSymbol) + if file == nil { + return false + } + return isFileForArbitraryExtension(file.FileName(), extension) +} + +func IsResolvedModuleForArbitraryExtension(resolvedModule *ResolvedModule, extension string) bool { + if resolvedModule.IsResolved() { + return isFileForArbitraryExtension(resolvedModule.ResolvedFileName, extension) + } + return false +} + +func IsResolvedModuleForExtension(resolvedModule *ResolvedModule, extension string) bool { + return resolvedModule.IsResolved() && tspath.FileExtensionIs(resolvedModule.ResolvedFileName, extension) +} + +func isFileForArbitraryExtension(fileName string, extension string) bool { + return tspath.FileExtensionIs(fileName, extension) || slices.Contains(tspath.GetPossibleOriginalInputExtensionForExtension(fileName), extension) +} + func IsApplicableVersionedTypesKey(key string) bool { if !strings.HasPrefix(key, "types@") { return false diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go index 8b53a39b0cda3..1bdc71d0c1bf3 100644 --- a/tsc/internal/parser/parser.go +++ b/tsc/internal/parser/parser.go @@ -2281,6 +2281,7 @@ func (p *Parser) parseImportDeclarationOrImportEqualsDeclaration(pos int, jsdoc afterImportPos := p.nodePos() // We don't parse the identifier here in await context, instead we will report a grammar error in the checker. saveHasAwaitIdentifier := p.statementHasAwaitIdentifier + phaseModifierCandidate := p.currentImportPhaseModifier() var identifier *ast.Node if p.isIdentifier() { identifier = p.parseIdentifier() @@ -2294,22 +2295,14 @@ func (p *Parser) parseImportDeclarationOrImportEqualsDeclaration(pos int, jsdoc if p.isIdentifier() { identifier = p.parseIdentifier() } - } else if identifier != nil && identifier.Text() == "defer" { - var shouldParseAsDeferModifier bool - if p.token == ast.KindFromKeyword { - shouldParseAsDeferModifier = !p.lookAhead((*Parser).nextTokenIsTokenStringLiteral) - } else { - shouldParseAsDeferModifier = p.token != ast.KindCommaToken && p.token != ast.KindEqualsToken - } - if shouldParseAsDeferModifier { - phaseModifier = ast.KindDeferKeyword - identifier = nil - if p.isIdentifier() { - identifier = p.parseIdentifier() - } + } else if identifier != nil && phaseModifierCandidate != ast.KindUnknown && p.shouldParseImportPhaseModifier() { + phaseModifier = phaseModifierCandidate + identifier = nil + if p.isIdentifier() { + identifier = p.parseIdentifier() } } - if identifier != nil && !p.tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() && phaseModifier != ast.KindDeferKeyword { + if identifier != nil && p.tokenAfterImportedIdentifierAllowsImportEqualsDeclaration() && phaseModifier != ast.KindDeferKeyword && phaseModifier != ast.KindSourceKeyword { importEquals := p.checkJSSyntax(p.parseImportEqualsDeclaration(pos, jsdoc, modifiers, identifier, phaseModifier == ast.KindTypeKeyword)) p.statementHasAwaitIdentifier = saveHasAwaitIdentifier // Import= declaration is always parsed in an Await context, no need to reparse return importEquals @@ -2330,14 +2323,40 @@ func (p *Parser) nextTokenIsFromKeywordOrEqualsToken() bool { return p.token == ast.KindFromKeyword || p.token == ast.KindEqualsToken } +func (p *Parser) shouldParseImportPhaseModifier() bool { + switch p.token { + case ast.KindCommaToken, ast.KindEqualsToken: + return false + case ast.KindFromKeyword: + if p.lookAhead((*Parser).nextTokenIsTokenStringLiteral) { + return false + } + } + return true +} + +func (p *Parser) currentImportPhaseModifier() ast.Kind { + switch p.scanner.TokenText() { + case "defer": + return ast.KindDeferKeyword + case "source": + return ast.KindSourceKeyword + default: + return ast.KindUnknown + } +} + func (p *Parser) tokenAfterImportDefinitelyProducesImportDeclaration() bool { return p.token == ast.KindAsteriskToken || p.token == ast.KindOpenBraceToken } -func (p *Parser) tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() bool { - // In `import id ___`, the current token decides whether to produce - // an ImportDeclaration or ImportEqualsDeclaration. - return p.token == ast.KindCommaToken || p.token == ast.KindFromKeyword +func (p *Parser) tokenAfterImportedIdentifierAllowsImportEqualsDeclaration() bool { + switch p.token { + case ast.KindCommaToken, ast.KindFromKeyword: + return false + default: + return true + } } func (p *Parser) parseImportEqualsDeclaration(pos int, jsdoc jsdocScannerInfo, modifiers *ast.ModifierList, identifier *ast.Node, isTypeOnly bool) *ast.Node { @@ -2387,6 +2406,9 @@ func (p *Parser) tryParseImportClause(identifier *ast.Node, pos int, phaseModifi p.parseExpected(ast.KindFromKeyword) return importClause } + if phaseModifier == ast.KindSourceKeyword { + return p.finishNode(p.factory.NewImportClause(phaseModifier, nil /*name*/, nil /*namedBindings*/), pos) + } return nil } @@ -5239,8 +5261,8 @@ func (p *Parser) parseLeftHandSideExpressionOrHigher() *ast.Expression { // This is an 'import.*' metaproperty (i.e. 'import.meta') p.nextToken() // advance past the 'import' p.nextToken() // advance past the dot - expression = p.finishNode(p.factory.NewMetaProperty(ast.KindImportKeyword, p.parseIdentifierName()), pos) - if expression.Text() == "defer" { + expression = p.finishNode(p.factory.NewMetaProperty(ast.KindImportKeyword, p.parseImportMetaPropertyName()), pos) + if ast.IsImportPhaseMetaProperty(expression) { if p.token == ast.KindOpenParenToken || p.token == ast.KindLessThanToken { p.sourceFlags |= ast.NodeFlagsPossiblyContainsDynamicImport } @@ -5265,6 +5287,16 @@ func (p *Parser) nextTokenIsDot() bool { return p.nextToken() == ast.KindDotToken } +func (p *Parser) parseImportMetaPropertyName() *ast.Node { + switch p.token { + case ast.KindDeferKeyword, ast.KindSourceKeyword: + if p.currentImportPhaseModifier() == ast.KindUnknown { + p.parseErrorAtCurrentToken(diagnostics.Keywords_cannot_contain_escape_characters) + } + } + return p.parseIdentifierName() +} + func (p *Parser) parseSuperExpression() *ast.Expression { pos := p.nodePos() expression := p.parseKeywordExpression() @@ -6102,7 +6134,7 @@ func (p *Parser) isStartOfStatement() bool { case ast.KindConstKeyword, ast.KindExportKeyword: return p.isStartOfDeclaration() case ast.KindAsyncKeyword, ast.KindDeclareKeyword, ast.KindInterfaceKeyword, ast.KindModuleKeyword, ast.KindNamespaceKeyword, - ast.KindTypeKeyword, ast.KindGlobalKeyword, ast.KindDeferKeyword: + ast.KindTypeKeyword, ast.KindGlobalKeyword, ast.KindDeferKeyword, ast.KindSourceKeyword: // When these don't start a declaration, they're an identifier in an expression statement return true case ast.KindAccessorKeyword, ast.KindPublicKeyword, ast.KindPrivateKeyword, ast.KindProtectedKeyword, ast.KindStaticKeyword, @@ -6151,7 +6183,7 @@ func (p *Parser) scanStartOfDeclaration() bool { // I {} // // could be legal, it would add complexity for very little gain. - case ast.KindInterfaceKeyword, ast.KindTypeKeyword, ast.KindDeferKeyword: + case ast.KindInterfaceKeyword, ast.KindTypeKeyword, ast.KindDeferKeyword, ast.KindSourceKeyword: return p.nextTokenIsIdentifierOnSameLine() case ast.KindModuleKeyword, ast.KindNamespaceKeyword: return p.nextTokenIsIdentifierOrStringLiteralOnSameLine() @@ -6174,7 +6206,7 @@ func (p *Parser) scanStartOfDeclaration() bool { return p.token == ast.KindOpenBraceToken || p.token == ast.KindIdentifier || p.token == ast.KindExportKeyword case ast.KindImportKeyword: p.nextToken() - return p.token == ast.KindDeferKeyword || p.token == ast.KindStringLiteral || p.token == ast.KindAsteriskToken || p.token == ast.KindOpenBraceToken || tokenIsIdentifierOrKeyword(p.token) + return p.token == ast.KindDeferKeyword || p.token == ast.KindSourceKeyword || p.token == ast.KindStringLiteral || p.token == ast.KindAsteriskToken || p.token == ast.KindOpenBraceToken || tokenIsIdentifierOrKeyword(p.token) case ast.KindExportKeyword: p.nextToken() if p.token == ast.KindEqualsToken || p.token == ast.KindAsteriskToken || p.token == ast.KindOpenBraceToken || diff --git a/tsc/internal/parser/parser_test.go b/tsc/internal/parser/parser_test.go index 200064160228b..fd905f87bbd3d 100644 --- a/tsc/internal/parser/parser_test.go +++ b/tsc/internal/parser/parser_test.go @@ -11,11 +11,13 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/ast" "github.com/microsoft/TypeScript/tsc/internal/collections" "github.com/microsoft/TypeScript/tsc/internal/core" + "github.com/microsoft/TypeScript/tsc/internal/diagnostics" "github.com/microsoft/TypeScript/tsc/internal/parser" "github.com/microsoft/TypeScript/tsc/internal/repo" "github.com/microsoft/TypeScript/tsc/internal/scanner" "github.com/microsoft/TypeScript/tsc/internal/testrunner" "github.com/microsoft/TypeScript/tsc/internal/testutil/fixtures" + "github.com/microsoft/TypeScript/tsc/internal/testutil/parsetestutil" "github.com/microsoft/TypeScript/tsc/internal/tspath" "github.com/microsoft/TypeScript/tsc/internal/vfs/osvfs" "gotest.tools/v3/assert" @@ -186,6 +188,198 @@ class MissingImplements implements B. {} assert.Equal(t, missingImplementsDecl.HeritageClauses.Nodes[0].AsHeritageClause().Types.Nodes[0].Kind, ast.KindExpressionWithTypeArguments) } +func TestParseStaticSourcePhaseImport(t *testing.T) { + t.Parallel() + tests := []struct { + name string + source string + phaseModifier ast.Kind + bindingName string + hasAttributes bool + }{ + { + name: "source phase", + source: `import source a from "./a.wasm";`, + phaseModifier: ast.KindSourceKeyword, + bindingName: "a", + }, + { + name: "source phase with import attributes", + source: `import source a from "./a.wasm" with { type: "webassembly" };`, + phaseModifier: ast.KindSourceKeyword, + bindingName: "a", + hasAttributes: true, + }, + { + name: "from as source phase binding", + source: `import source from from "./module.js";`, + phaseModifier: ast.KindSourceKeyword, + bindingName: "from", + }, + { + name: "source as ordinary default binding", + source: `import source from "./module.js";`, + phaseModifier: ast.KindUnknown, + bindingName: "source", + }, + { + name: "source as ordinary default binding with named imports", + source: `import source, { value } from "./module.js";`, + phaseModifier: ast.KindUnknown, + bindingName: "source", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + file := parsetestutil.ParseTypeScript(test.source, false) + parsetestutil.CheckDiagnostics(t, file) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsImportDeclaration(statement)) + + declaration := statement.AsImportDeclaration() + assert.Assert(t, declaration.ImportClause != nil) + + clause := declaration.ImportClause.AsImportClause() + assert.Equal(t, clause.PhaseModifier, test.phaseModifier) + assert.Assert(t, clause.Name() != nil) + assert.Equal(t, clause.Name().Text(), test.bindingName) + assert.Equal(t, declaration.Attributes != nil, test.hasAttributes) + }) + } +} + +func TestParseEscapedImportPhaseAsDefaultBinding(t *testing.T) { + t.Parallel() + tests := []struct { + source string + bindingName string + }{ + {source: `import d\u0065fer from "./module.js";`, bindingName: "defer"}, + {source: `import s\u006furce from "./module.js";`, bindingName: "source"}, + } + + for _, test := range tests { + t.Run(test.bindingName, func(t *testing.T) { + t.Parallel() + file := parsetestutil.ParseTypeScript(test.source, false) + parsetestutil.CheckDiagnostics(t, file) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsImportDeclaration(statement)) + + clause := statement.AsImportDeclaration().ImportClause.AsImportClause() + assert.Equal(t, clause.PhaseModifier, ast.KindUnknown) + assert.Equal(t, clause.Name().Text(), test.bindingName) + }) + } +} + +func TestParseSourceAsImportEqualsBinding(t *testing.T) { + t.Parallel() + file := parsetestutil.ParseTypeScript(`import source = require("./module.js");`, false) + parsetestutil.CheckDiagnostics(t, file) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsImportEqualsDeclaration(statement)) + + assert.Equal(t, statement.Name().Text(), "source") +} + +func TestParseInvalidStaticSourcePhaseImports(t *testing.T) { + t.Parallel() + tests := []struct { + source string + hasName bool + hasNamedBindings bool + }{ + {source: `import source "./a.js";`}, + {source: `import source * as a from "./a.js";`, hasNamedBindings: true}, + {source: `import source { a } from "./a.js";`, hasNamedBindings: true}, + {source: `import source a, { b } from "./a.js";`, hasName: true, hasNamedBindings: true}, + } + + for _, test := range tests { + file := parsetestutil.ParseTypeScript(test.source, false) + parsetestutil.CheckDiagnostics(t, file) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsImportDeclaration(statement)) + + declaration := statement.AsImportDeclaration() + assert.Assert(t, declaration.ImportClause != nil) + + clause := declaration.ImportClause.AsImportClause() + assert.Equal(t, clause.PhaseModifier, ast.KindSourceKeyword) + assert.Equal(t, clause.Name() != nil, test.hasName) + assert.Equal(t, clause.NamedBindings != nil, test.hasNamedBindings) + } +} + +func TestParseDynamicSourcePhaseImport(t *testing.T) { + t.Parallel() + file := parsetestutil.ParseTypeScript(`import.source("./a.wasm", { with: { type: "webassembly" } });`, false) + parsetestutil.CheckDiagnostics(t, file) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsExpressionStatement(statement)) + + call := statement.AsExpressionStatement().Expression + assert.Assert(t, ast.IsCallExpression(call)) + assert.Assert(t, ast.IsImportCall(call)) + assert.Assert(t, call.SubtreeFacts()&ast.SubtreeContainsDynamicImport != 0) + + metaProperty := call.Expression() + assert.Assert(t, ast.IsMetaProperty(metaProperty)) + assert.Equal(t, metaProperty.AsMetaProperty().KeywordToken, ast.KindImportKeyword) + assert.Equal(t, metaProperty.Text(), "source") + assert.Equal(t, len(call.Arguments()), 2) + assert.Equal(t, file.Flags&ast.NodeFlagsPossiblyContainsDynamicImport != 0, true) + assert.Equal(t, file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, false) + assert.Equal(t, file.ExternalModuleIndicator == nil, true) +} + +func TestParseEscapedDynamicImportPhase(t *testing.T) { + t.Parallel() + tests := []struct { + source string + phaseName string + }{ + {source: `import.d\u0065fer("./a.js");`, phaseName: "defer"}, + {source: `import.s\u006furce("./a.wasm");`, phaseName: "source"}, + } + + for _, test := range tests { + t.Run(test.phaseName, func(t *testing.T) { + t.Parallel() + file := parsetestutil.ParseTypeScript(test.source, false) + assert.Equal(t, len(file.Diagnostics()), 1) + assert.Equal(t, file.Diagnostics()[0].Code(), diagnostics.Keywords_cannot_contain_escape_characters.Code()) + assert.Equal(t, len(file.Statements.Nodes), 1) + + statement := file.Statements.Nodes[0] + assert.Assert(t, ast.IsExpressionStatement(statement)) + + call := statement.AsExpressionStatement().Expression + assert.Assert(t, ast.IsCallExpression(call)) + assert.Assert(t, ast.IsImportCall(call)) + + metaProperty := call.Expression() + assert.Assert(t, ast.IsMetaProperty(metaProperty)) + assert.Equal(t, metaProperty.Text(), test.phaseName) + assert.Equal(t, file.Flags&ast.NodeFlagsPossiblyContainsDynamicImport != 0, true) + assert.Equal(t, file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, false) + }) + } +} + func TestJSDocImportTypeParentChain(t *testing.T) { t.Parallel() sourceText := `test("", async function () { diff --git a/tsc/internal/printer/printer.go b/tsc/internal/printer/printer.go index 6f0386780975f..cfd724b3f6132 100644 --- a/tsc/internal/printer/printer.go +++ b/tsc/internal/printer/printer.go @@ -3013,8 +3013,8 @@ func (p *Printer) emitNonNullExpression(node *ast.NonNullExpression) { func (p *Printer) emitMetaProperty(node *ast.MetaProperty) { state := p.enterNode(node.AsNode()) - p.emitToken(node.KeywordToken, node.Pos(), WriteKindPunctuation, node.AsNode()) - p.writePunctuation(".") + pos := p.emitToken(node.KeywordToken, node.Pos(), WriteKindPunctuation, node.AsNode()) + p.emitToken(ast.KindDotToken, pos, WriteKindPunctuation, node.AsNode()) p.emitIdentifierName(node.Name().AsIdentifier()) p.exitNode(node.AsNode(), state) } diff --git a/tsc/internal/scanner/scanner.go b/tsc/internal/scanner/scanner.go index 6958b4ab09246..50ac3a901aec0 100644 --- a/tsc/internal/scanner/scanner.go +++ b/tsc/internal/scanner/scanner.go @@ -96,6 +96,7 @@ var textToKeyword = map[string]ast.Kind{ "return": ast.KindReturnKeyword, "satisfies": ast.KindSatisfiesKeyword, "set": ast.KindSetKeyword, + "source": ast.KindSourceKeyword, "static": ast.KindStaticKeyword, "string": ast.KindStringKeyword, "super": ast.KindSuperKeyword, diff --git a/tsc/internal/scanner/scanner_test.go b/tsc/internal/scanner/scanner_test.go index 5c50a17fe0f59..8f970f2af8467 100644 --- a/tsc/internal/scanner/scanner_test.go +++ b/tsc/internal/scanner/scanner_test.go @@ -91,3 +91,15 @@ func TestGetTextOfNodeFromJSDocTypePreservesAsteriskType(t *testing.T) { assert.Equal(t, GetTextOfNodeFromSourceText(sourceText, node, false /*includeTrivia*/), "*") } + +func TestScanSourceKeyword(t *testing.T) { + t.Parallel() + s := NewScanner() + s.SetText("source sourceValue") + + assert.Equal(t, s.Scan(), ast.KindSourceKeyword) + assert.Equal(t, TokenToString(ast.KindSourceKeyword), "source") + assert.Equal(t, StringToToken("source"), ast.KindSourceKeyword) + assert.Equal(t, s.Scan(), ast.KindIdentifier) + assert.Equal(t, s.TokenValue(), "sourceValue") +} diff --git a/tsc/internal/testutil/tsbaseline/js_emit_baseline.go b/tsc/internal/testutil/tsbaseline/js_emit_baseline.go index aaee3fb601fdd..902bb2ab3588a 100644 --- a/tsc/internal/testutil/tsbaseline/js_emit_baseline.go +++ b/tsc/internal/testutil/tsbaseline/js_emit_baseline.go @@ -221,7 +221,7 @@ func prepareDeclarationCompilationContext( } addDtsFile := func(file *harnessutil.TestFile, dtsFiles []*harnessutil.TestFile) []*harnessutil.TestFile { - if tspath.IsDeclarationFileName(file.UnitName) || tspath.HasJSONFileExtension(file.UnitName) { + if tspath.IsDeclarationFileName(file.UnitName) || tspath.HasJSONFileExtension(file.UnitName) || tspath.FileExtensionIs(file.UnitName, tspath.ExtensionWasm) { dtsFiles = append(dtsFiles, file) } else if sourceFile := result.Program.GetSourceFile(file.UnitName); sourceFile != nil && (tspath.HasTSFileExtension(file.UnitName) || (tspath.HasJSFileExtension(file.UnitName) && options.GetAllowJS()) || sourceFile.ContentMapper() != "") { diff --git a/tsc/internal/transformers/moduletransforms/commonjsmodule.go b/tsc/internal/transformers/moduletransforms/commonjsmodule.go index 9e7ca97dbe241..31eccec02990b 100644 --- a/tsc/internal/transformers/moduletransforms/commonjsmodule.go +++ b/tsc/internal/transformers/moduletransforms/commonjsmodule.go @@ -1807,7 +1807,7 @@ func (tx *CommonJSModuleTransformer) visitCallExpression(node *ast.CallExpressio needsRewrite = true } } - if ast.IsImportCall(node.AsNode()) && tx.shouldTransformImportCall() { + if node.Expression.Kind == ast.KindImportKeyword && tx.shouldTransformImportCall() { return tx.visitImportCallExpression(node, needsRewrite) } if needsRewrite { diff --git a/tsc/internal/tspath/extension.go b/tsc/internal/tspath/extension.go index 1c17fa4b0bea8..4e1df33d9c285 100644 --- a/tsc/internal/tspath/extension.go +++ b/tsc/internal/tspath/extension.go @@ -12,6 +12,7 @@ const ( ExtensionJs = ".js" ExtensionJsx = ".jsx" ExtensionJson = ".json" + ExtensionWasm = ".wasm" ExtensionTsBuildInfo = ".tsbuildinfo" ExtensionMjs = ".mjs" ExtensionMts = ".mts" diff --git a/tsc/testdata/baselines/reference/conformance/importMetaPropertyInvalidInCall.errors.txt b/tsc/testdata/baselines/reference/conformance/importMetaPropertyInvalidInCall.errors.txt index 6ab3da50174a8..6689fa7521928 100644 --- a/tsc/testdata/baselines/reference/conformance/importMetaPropertyInvalidInCall.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/importMetaPropertyInvalidInCall.errors.txt @@ -1,11 +1,11 @@ -b.ts(1,8): error TS18061: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta' or 'defer'? +b.ts(1,8): error TS100073: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? b.ts(2,8): error TS17012: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta'? ==== b.ts (2 errors) ==== import.foo(); ~~~ -!!! error TS18061: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta' or 'defer'? +!!! error TS100073: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? import.foo; ~~~ !!! error TS17012: 'foo' is not a valid meta-property for keyword 'import'. Did you mean 'meta'? diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).js b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).js new file mode 100644 index 0000000000000..37da46424bb6f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; + +//// [c.ts] +import source a from "./a.wasm" with { type: "webassembly" }; +const b: WebAssembly.Module = a; + + +//// [b.js] +import source a from "./a.wasm"; +const b = a; +//// [c.js] +import source a from "./a.wasm" with { type: "webassembly" }; +const b = a; diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).symbols b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).symbols new file mode 100644 index 0000000000000..eb266d5e8ef5f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).symbols @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(b.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +=== c.ts === +import source a from "./a.wasm" with { type: "webassembly" }; +>a : Symbol(a, Decl(c.ts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(c.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 0, 6)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).types b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).types new file mode 100644 index 0000000000000..0304d9e0991be --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=esnext).types @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +=== c.ts === +import source a from "./a.wasm" with { type: "webassembly" }; +>a : WebAssembly.Module +>type : error + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).js b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).js new file mode 100644 index 0000000000000..37da46424bb6f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; + +//// [c.ts] +import source a from "./a.wasm" with { type: "webassembly" }; +const b: WebAssembly.Module = a; + + +//// [b.js] +import source a from "./a.wasm"; +const b = a; +//// [c.js] +import source a from "./a.wasm" with { type: "webassembly" }; +const b = a; diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).symbols b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).symbols new file mode 100644 index 0000000000000..eb266d5e8ef5f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).symbols @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(b.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +=== c.ts === +import source a from "./a.wasm" with { type: "webassembly" }; +>a : Symbol(a, Decl(c.ts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(c.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 0, 6)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).types b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).types new file mode 100644 index 0000000000000..0304d9e0991be --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource1(module=preserve).types @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/importSource/importSource1.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +=== c.ts === +import source a from "./a.wasm" with { type: "webassembly" }; +>a : WebAssembly.Module +>type : error + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + diff --git a/tsc/testdata/baselines/reference/conformance/importSource10.js b/tsc/testdata/baselines/reference/conformance/importSource10.js new file mode 100644 index 0000000000000..0cb8e39e9d6a0 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource10.js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/importSource/importSource10.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.wasm"; +export { a }; + +//// [c.ts] +import { a } from "./b.js"; +const b: WebAssembly.Module = a; + +//// [d.ts] +import * as a from "./b.js"; +const b: WebAssembly.Module = a.a; + + +//// [b.js] +import source a from "./a.wasm"; +export { a }; +//// [c.js] +import { a } from "./b.js"; +const b = a; +//// [d.js] +import * as a from "./b.js"; +const b = a.a; + + +//// [b.d.ts] +import source a from "./a.wasm"; +export { a }; +//// [c.d.ts] +export {}; +//// [d.d.ts] +export {}; diff --git a/tsc/testdata/baselines/reference/conformance/importSource10.symbols b/tsc/testdata/baselines/reference/conformance/importSource10.symbols new file mode 100644 index 0000000000000..6401e446c8303 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource10.symbols @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/importSource/importSource10.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export { a }; +>a : Symbol(a, Decl(b.ts, 1, 8)) + +=== c.ts === +import { a } from "./b.js"; +>a : Symbol(a, Decl(c.ts, 0, 8)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(c.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 0, 8)) + +=== d.ts === +import * as a from "./b.js"; +>a : Symbol(a, Decl(d.ts, 0, 6)) + +const b: WebAssembly.Module = a.a; +>b : Symbol(b, Decl(d.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a.a : Symbol(a.a, Decl(b.ts, 1, 8)) +>a : Symbol(a, Decl(d.ts, 0, 6)) +>a : Symbol(a.a, Decl(b.ts, 1, 8)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource10.types b/tsc/testdata/baselines/reference/conformance/importSource10.types new file mode 100644 index 0000000000000..5dca8b9208f52 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource10.types @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/importSource/importSource10.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +export { a }; +>a : WebAssembly.Module + +=== c.ts === +import { a } from "./b.js"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +=== d.ts === +import * as a from "./b.js"; +>a : typeof a + +const b: WebAssembly.Module = a.a; +>b : WebAssembly.Module +>WebAssembly : any +>a.a : WebAssembly.Module +>a : typeof a +>a : WebAssembly.Module + diff --git a/tsc/testdata/baselines/reference/conformance/importSource11.js b/tsc/testdata/baselines/reference/conformance/importSource11.js new file mode 100644 index 0000000000000..a567088e7c4c4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource11.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource11.ts] //// + +//// [a.ts] +export const a = 1; + +//// [b.ts] +import source a from "./a.js"; +const b = import.source("./a.js"); + +const c: any = a; +const d: Promise = b; + + +//// [a.js] +export const a = 1; +//// [b.js] +import source a from "./a.js"; +const b = import.source("./a.js"); +const c = a; +const d = b; diff --git a/tsc/testdata/baselines/reference/conformance/importSource11.symbols b/tsc/testdata/baselines/reference/conformance/importSource11.symbols new file mode 100644 index 0000000000000..1a08e68fe4336 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource11.symbols @@ -0,0 +1,23 @@ +//// [tests/cases/conformance/importSource/importSource11.ts] //// + +=== a.ts === +export const a = 1; +>a : Symbol(a, Decl(a.ts, 0, 12)) + +=== b.ts === +import source a from "./a.js"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b = import.source("./a.js"); +>b : Symbol(b, Decl(b.ts, 1, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +const c: any = a; +>c : Symbol(c, Decl(b.ts, 3, 5)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const d: Promise = b; +>d : Symbol(d, Decl(b.ts, 4, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>b : Symbol(b, Decl(b.ts, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource11.types b/tsc/testdata/baselines/reference/conformance/importSource11.types new file mode 100644 index 0000000000000..a49351f50bfca --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource11.types @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/importSource/importSource11.ts] //// + +=== a.ts === +export const a = 1; +>a : 1 +>1 : 1 + +=== b.ts === +import source a from "./a.js"; +>a : any + +const b = import.source("./a.js"); +>b : Promise +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +const c: any = a; +>c : any +>a : any + +const d: Promise = b; +>d : Promise +>b : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource12.js b/tsc/testdata/baselines/reference/conformance/importSource12.js new file mode 100644 index 0000000000000..0cad70ec877ff --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource12.js @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importSource/importSource12.ts] //// + +//// [a.ts] +export {}; + +//// [b.ts] +import source a from "./a.ts"; +export { a }; +export const b = import.source("./a.ts"); + + +//// [a.js] +//// [b.js] +import source a from "./a.js"; +export { a }; +export const b = import.source("./a.js"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource12.symbols b/tsc/testdata/baselines/reference/conformance/importSource12.symbols new file mode 100644 index 0000000000000..f77f9030443b9 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource12.symbols @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/importSource/importSource12.ts] //// + +=== a.ts === + +export {}; + +=== b.ts === +import source a from "./a.ts"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export { a }; +>a : Symbol(a, Decl(b.ts, 1, 8)) + +export const b = import.source("./a.ts"); +>b : Symbol(b, Decl(b.ts, 2, 12)) +>"./a.ts" : Symbol("./a.ts", Decl(a.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource12.types b/tsc/testdata/baselines/reference/conformance/importSource12.types new file mode 100644 index 0000000000000..32671b7b16da6 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource12.types @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importSource/importSource12.ts] //// + +=== a.ts === + +export {}; + +=== b.ts === +import source a from "./a.ts"; +>a : any + +export { a }; +>a : any + +export const b = import.source("./a.ts"); +>b : Promise +>import.source("./a.ts") : Promise +>source : any +>"./a.ts" : "./a.ts" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource13.js b/tsc/testdata/baselines/reference/conformance/importSource13.js new file mode 100644 index 0000000000000..668fbc0d49997 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource13.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/importSource/importSource13.ts] //// + +//// [a.d.ts] +declare module "*.wasm"; + +//// [b.ts] +import source a from "./a.wasm"; +const b: any = a; +const c: Promise = import.source("./a.wasm"); + + +//// [b.js] +import source a from "./a.wasm"; +const b = a; +const c = import.source("./a.wasm"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource13.symbols b/tsc/testdata/baselines/reference/conformance/importSource13.symbols new file mode 100644 index 0000000000000..ea5ebd1dcad51 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource13.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importSource/importSource13.ts] //// + +=== a.d.ts === +declare module "*.wasm"; +>"*.wasm" : Symbol("*.wasm", Decl(a.d.ts, 0, 0)) + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b: any = a; +>b : Symbol(b, Decl(b.ts, 1, 5)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const c: Promise = import.source("./a.wasm"); +>c : Symbol(c, Decl(b.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>"./a.wasm" : Symbol("*.wasm", Decl(a.d.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource13.types b/tsc/testdata/baselines/reference/conformance/importSource13.types new file mode 100644 index 0000000000000..21f46596698b5 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource13.types @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource13.ts] //// + +=== a.d.ts === +declare module "*.wasm"; +>"*.wasm" : any + +=== b.ts === +import source a from "./a.wasm"; +>a : any + +const b: any = a; +>b : any +>a : any + +const c: Promise = import.source("./a.wasm"); +>c : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource14.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource14.errors.txt new file mode 100644 index 0000000000000..dd9e22eaff056 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource14.errors.txt @@ -0,0 +1,18 @@ +b.ts(1,22): error TS6263: Module './a.txt' was resolved to 'a.d.txt.ts', but '--allowArbitraryExtensions' is not set. +b.ts(2,25): error TS6263: Module './a.txt' was resolved to 'a.d.txt.ts', but '--allowArbitraryExtensions' is not set. + + +==== a.d.txt.ts (0 errors) ==== + export {}; + +==== b.ts (2 errors) ==== + import source a from "./a.txt"; + ~~~~~~~~~ +!!! error TS6263: Module './a.txt' was resolved to 'a.d.txt.ts', but '--allowArbitraryExtensions' is not set. + const b = import.source("./a.txt"); + ~~~~~~~~~ +!!! error TS6263: Module './a.txt' was resolved to 'a.d.txt.ts', but '--allowArbitraryExtensions' is not set. + + a; + b; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource14.js b/tsc/testdata/baselines/reference/conformance/importSource14.js new file mode 100644 index 0000000000000..7171407f868bb --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource14.js @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource14.ts] //// + +//// [a.d.txt.ts] +export {}; + +//// [b.ts] +import source a from "./a.txt"; +const b = import.source("./a.txt"); + +a; +b; + + +//// [b.js] +import source a from "./a.txt"; +const b = import.source("./a.txt"); +a; +b; diff --git a/tsc/testdata/baselines/reference/conformance/importSource14.symbols b/tsc/testdata/baselines/reference/conformance/importSource14.symbols new file mode 100644 index 0000000000000..5c3b8d07a3c51 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource14.symbols @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource14.ts] //// + +=== a.d.txt.ts === + +export {}; + +=== b.ts === +import source a from "./a.txt"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b = import.source("./a.txt"); +>b : Symbol(b, Decl(b.ts, 1, 5)) +>"./a.txt" : Symbol("./a.txt", Decl(a.d.txt.ts, 0, 0)) + +a; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +b; +>b : Symbol(b, Decl(b.ts, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource14.types b/tsc/testdata/baselines/reference/conformance/importSource14.types new file mode 100644 index 0000000000000..92e0eb6c03fd0 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource14.types @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/importSource/importSource14.ts] //// + +=== a.d.txt.ts === + +export {}; + +=== b.ts === +import source a from "./a.txt"; +>a : any + +const b = import.source("./a.txt"); +>b : Promise +>import.source("./a.txt") : Promise +>source : any +>"./a.txt" : "./a.txt" + +a; +>a : any + +b; +>b : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource15.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource15.errors.txt new file mode 100644 index 0000000000000..2f1122c388847 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource15.errors.txt @@ -0,0 +1,107 @@ +b.js(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +c.js(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +d.js(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +e.js(1,8): error TS100069: A source phase import must specify a local binding. +f.js(1,14): error TS1005: '(' expected. +f.js(2,15): error TS1005: '(' expected. +f.js(3,23): error TS1005: '(' expected. +f.js(4,14): error TS1005: '(' expected. +f.js(6,1): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments +f.js(7,1): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments +f.js(8,14): error TS100072: Optional chaining cannot be used with 'import.source'. +f.js(9,14): error TS1005: '(' expected. +f.js(10,15): error TS1325: Argument of dynamic import cannot be spread element. +g.js(1,5): error TS1109: Expression expected. +h.js(1,21): error TS1005: '(' expected. +i.js(1,8): error TS100073: 'a' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? +m.js(1,8): error TS1260: Keywords cannot contain escape characters. + + +==== a.js (0 errors) ==== + export default 1; + export const a = 2; + +==== b.js (1 errors) ==== + import source * as a from "./a.js"; + ~~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== c.js (1 errors) ==== + import source { a } from "./a.js"; + ~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== d.js (1 errors) ==== + import source a, { a as b } from "./a.js"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== e.js (1 errors) ==== + import source "./a.js"; + ~~~~~~ +!!! error TS100069: A source phase import must specify a local binding. + +==== f.js (9 errors) ==== + import.source; + +!!! error TS1005: '(' expected. + (import.source)("./a.js"); + +!!! error TS1005: '(' expected. + Function(import.source); + +!!! error TS1005: '(' expected. + import.source.unknown; + +!!! error TS1005: '(' expected. + + import.source(); + ~~~~~~~~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments + import.source("./a.js", {}, {}); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments + import.source?.("./a.js"); + ~~ +!!! error TS100072: Optional chaining cannot be used with 'import.source'. + import.source("./a.js"); + +!!! error TS1005: '(' expected. + import.source(...["./a.js"]); + ~~~~~~~~~~~~~ +!!! error TS1325: Argument of dynamic import cannot be spread element. + +==== g.js (1 errors) ==== + new import.source("./a.js"); + ~~~~~~ +!!! error TS1109: Expression expected. + +==== h.js (1 errors) ==== + typeof import.source; + +!!! error TS1005: '(' expected. + +==== i.js (1 errors) ==== + import.a("./a.js"); + ~ +!!! error TS100073: 'a' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? + +==== j.js (0 errors) ==== + import source a from "./a.js" with { type: "javascript" }; + const b = import.source("./a.js", { with: { type: "javascript" } }); + a; + b; + +==== k.js (0 errors) ==== + const a = import.source("./a.js", { with: { type: "javascript" } }); + a; + +==== l.js (0 errors) ==== + import s\u006furce from "./a.js"; + source; + +==== m.js (1 errors) ==== + import.s\u006furce("./a.js"); + ~~~~~~~~~~~ +!!! error TS1260: Keywords cannot contain escape characters. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource15.symbols b/tsc/testdata/baselines/reference/conformance/importSource15.symbols new file mode 100644 index 0000000000000..a0b7063582707 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource15.symbols @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/importSource/importSource15.ts] //// + +=== a.js === +export default 1; +export const a = 2; +>a : Symbol(a, Decl(a.js, 1, 12)) + +=== b.js === +import source * as a from "./a.js"; +>a : Symbol(a, Decl(b.js, 0, 13)) + +=== c.js === +import source { a } from "./a.js"; +>a : Symbol(a, Decl(c.js, 0, 15)) + +=== d.js === +import source a, { a as b } from "./a.js"; +>a : Symbol(a, Decl(d.js, 0, 6)) +>a : Symbol(b, Decl(a.js, 1, 12)) +>b : Symbol(b, Decl(d.js, 0, 18)) + +=== e.js === + +import source "./a.js"; + +=== f.js === +import.source; +(import.source)("./a.js"); +Function(import.source); +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.decorators.d.ts, --, --)) + +import.source.unknown; + +import.source(); +import.source("./a.js", {}, {}); +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + +import.source?.("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + +import.source("./a.js"); +import.source(...["./a.js"]); + +=== g.js === +new import.source("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + +=== h.js === + +typeof import.source; + +=== i.js === + +import.a("./a.js"); + +=== j.js === +import source a from "./a.js" with { type: "javascript" }; +>a : Symbol(a, Decl(j.js, 0, 6)) + +const b = import.source("./a.js", { with: { type: "javascript" } }); +>b : Symbol(b, Decl(j.js, 1, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) +>with : Symbol(with, Decl(j.js, 1, 35)) +>type : Symbol(type, Decl(j.js, 1, 43)) + +a; +>a : Symbol(a, Decl(j.js, 0, 6)) + +b; +>b : Symbol(b, Decl(j.js, 1, 5)) + +=== k.js === +const a = import.source("./a.js", { with: { type: "javascript" } }); +>a : Symbol(a, Decl(k.js, 0, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) +>with : Symbol(with, Decl(k.js, 0, 35)) +>type : Symbol(type, Decl(k.js, 0, 43)) + +a; +>a : Symbol(a, Decl(k.js, 0, 5)) + +=== l.js === +import s\u006furce from "./a.js"; +>s\u006furce : Symbol(s\u006furce, Decl(l.js, 0, 6)) + +source; +>source : Symbol(s\u006furce, Decl(l.js, 0, 6)) + +=== m.js === +import.s\u006furce("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource15.types b/tsc/testdata/baselines/reference/conformance/importSource15.types new file mode 100644 index 0000000000000..ca59cdfd9dffb --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource15.types @@ -0,0 +1,153 @@ +//// [tests/cases/conformance/importSource/importSource15.ts] //// + +=== a.js === +export default 1; +export const a = 2; +>a : 2 +>2 : 2 + +=== b.js === +import source * as a from "./a.js"; +>a : typeof a + +=== c.js === +import source { a } from "./a.js"; +>a : 2 + +=== d.js === +import source a, { a as b } from "./a.js"; +>a : any +>a : 2 +>b : 2 + +=== e.js === + +import source "./a.js"; + +=== f.js === +import.source; +>import.source : any +>source : any + +(import.source)("./a.js"); +>(import.source)("./a.js") : any +>(import.source) : any +>import.source : any +>source : any +>"./a.js" : "./a.js" + +Function(import.source); +>Function(import.source) : Function +>Function : FunctionConstructor +>import.source : any +>source : any + +import.source.unknown; +>import.source.unknown : any +>import.source : any +>source : any +>unknown : any + +import.source(); +>import.source() : Promise +>source : any + +import.source("./a.js", {}, {}); +>import.source("./a.js", {}, {}) : Promise +>source : any +>"./a.js" : "./a.js" +>{} : {} +>{} : {} + +import.source?.("./a.js"); +>import.source?.("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +import.source("./a.js"); +>import.source("./a.js") : boolean +>import.sourceimport.source : any +>source : any +>string : any +>("./a.js") : "./a.js" +>"./a.js" : "./a.js" + +import.source(...["./a.js"]); +>import.source(...["./a.js"]) : Promise +>source : any +>...["./a.js"] : string +>["./a.js"] : [string] +>"./a.js" : "./a.js" + +=== g.js === +new import.source("./a.js"); +>new : any +> : any +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +=== h.js === +typeof import.source; +>typeof import.source : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" +>import.source : any +>source : any + +=== i.js === +import.a("./a.js"); +>import.a("./a.js") : any +>import.a : any +>a : any +>"./a.js" : "./a.js" + +=== j.js === +import source a from "./a.js" with { type: "javascript" }; +>a : any +>type : any + +const b = import.source("./a.js", { with: { type: "javascript" } }); +>b : Promise +>import.source("./a.js", { with: { type: "javascript" } }) : Promise +>source : any +>"./a.js" : "./a.js" +>{ with: { type: "javascript" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "javascript" } : { type: string; } +>type : string +>"javascript" : "javascript" + +a; +>a : any + +b; +>b : Promise + +=== k.js === +const a = import.source("./a.js", { with: { type: "javascript" } }); +>a : Promise +>import.source("./a.js", { with: { type: "javascript" } }) : Promise +>source : any +>"./a.js" : "./a.js" +>{ with: { type: "javascript" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "javascript" } : { type: string; } +>type : string +>"javascript" : "javascript" + +a; +>a : Promise + +=== l.js === +import s\u006furce from "./a.js"; +>s\u006furce : 1 + +source; +>source : 1 + +=== m.js === +import.s\u006furce("./a.js"); +>import.s\u006furce("./a.js") : Promise +>s\u006furce : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource16.js b/tsc/testdata/baselines/reference/conformance/importSource16.js new file mode 100644 index 0000000000000..edd296d383085 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource16.js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/importSource/importSource16.ts] //// + +//// [a.wasm] + +//// [b.ts] +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +export type B = typeof a; +export { a }; + +export const c = import.source("./a.wasm"); +const d: Promise = c; + +//// [c.ts] +import { a, c } from "./b.js"; +const e: WebAssembly.Module = a; +const f: Promise = c; + + +//// [b.js] +import source a from "./a.wasm"; +const b = a; +export { a }; +export const c = import.source("./a.wasm"); +const d = c; +//// [c.js] +import { a, c } from "./b.js"; +const e = a; +const f = c; + + +//// [b.d.ts] +import source a from "./a.wasm"; +export type B = typeof a; +export { a }; +export declare const c: Promise; +//// [c.d.ts] +export {}; diff --git a/tsc/testdata/baselines/reference/conformance/importSource16.symbols b/tsc/testdata/baselines/reference/conformance/importSource16.symbols new file mode 100644 index 0000000000000..9e2d43178a0af --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource16.symbols @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/importSource/importSource16.ts] //// + +=== c.ts === +import { a, c } from "./b.js"; +>a : Symbol(a, Decl(c.ts, 0, 8)) +>c : Symbol(c, Decl(c.ts, 0, 11)) + +const e: WebAssembly.Module = a; +>e : Symbol(e, Decl(c.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 0, 8)) + +const f: Promise = c; +>f : Symbol(f, Decl(c.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>c : Symbol(c, Decl(c.ts, 0, 11)) + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(b.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export type B = typeof a; +>B : Symbol(B, Decl(b.ts, 1, 32)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export { a }; +>a : Symbol(a, Decl(b.ts, 3, 8)) + +export const c = import.source("./a.wasm"); +>c : Symbol(c, Decl(b.ts, 5, 12)) + +const d: Promise = c; +>d : Symbol(d, Decl(b.ts, 6, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>c : Symbol(c, Decl(b.ts, 5, 12)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource16.types b/tsc/testdata/baselines/reference/conformance/importSource16.types new file mode 100644 index 0000000000000..a5778d8ba38f6 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource16.types @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/importSource/importSource16.ts] //// + +=== c.ts === +import { a, c } from "./b.js"; +>a : WebAssembly.Module +>c : Promise + +const e: WebAssembly.Module = a; +>e : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +const f: Promise = c; +>f : Promise +>WebAssembly : any +>c : Promise + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +export type B = typeof a; +>B : WebAssembly.Module +>a : WebAssembly.Module + +export { a }; +>a : WebAssembly.Module + +export const c = import.source("./a.wasm"); +>c : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +const d: Promise = c; +>d : Promise +>WebAssembly : any +>c : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource17.symbols b/tsc/testdata/baselines/reference/conformance/importSource17.symbols new file mode 100644 index 0000000000000..4b0c3ece75f94 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource17.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importSource/importSource17.ts] //// + +=== b.js === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.js, 0, 6)) + +const b = import.source("./a.wasm"); +>b : Symbol(b, Decl(b.js, 1, 5)) + +/** @type {WebAssembly.Module} */ +const c = a; +>c : Symbol(c, Decl(b.js, 4, 5)) +>a : Symbol(a, Decl(b.js, 0, 6)) + +/** @type {Promise} */ +const d = b; +>d : Symbol(d, Decl(b.js, 7, 5)) +>b : Symbol(b, Decl(b.js, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource17.types b/tsc/testdata/baselines/reference/conformance/importSource17.types new file mode 100644 index 0000000000000..7b320526a4dc0 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource17.types @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/importSource/importSource17.ts] //// + +=== b.js === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b = import.source("./a.wasm"); +>b : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +/** @type {WebAssembly.Module} */ +const c = a; +>c : WebAssembly.Module +>a : WebAssembly.Module + +/** @type {Promise} */ +const d = b; +>d : Promise +>b : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource18.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource18.errors.txt new file mode 100644 index 0000000000000..93a5e7f6f3bec --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource18.errors.txt @@ -0,0 +1,14 @@ +b.ts(2,19): error TS2307: Cannot find module './a.wasm' or its corresponding type declarations. + + +==== b.ts (1 errors) ==== + import source a from "./a.wasm"; + import { b } from "./a.wasm"; + ~~~~~~~~~~ +!!! error TS2307: Cannot find module './a.wasm' or its corresponding type declarations. + + const c: WebAssembly.Module = a; + b; + +==== a.wasm (0 errors) ==== + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource18.js b/tsc/testdata/baselines/reference/conformance/importSource18.js new file mode 100644 index 0000000000000..5e2f9e52c0d9f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource18.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/importSource/importSource18.ts] //// + +//// [a.wasm] + +//// [b.ts] +import source a from "./a.wasm"; +import { b } from "./a.wasm"; + +const c: WebAssembly.Module = a; +b; + + +//// [b.js] +import source a from "./a.wasm"; +import { b } from "./a.wasm"; +const c = a; +b; diff --git a/tsc/testdata/baselines/reference/conformance/importSource18.symbols b/tsc/testdata/baselines/reference/conformance/importSource18.symbols new file mode 100644 index 0000000000000..c25f1092d9b62 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource18.symbols @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource18.ts] //// + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +import { b } from "./a.wasm"; +>b : Symbol(b, Decl(b.ts, 1, 8)) + +const c: WebAssembly.Module = a; +>c : Symbol(c, Decl(b.ts, 3, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +b; +>b : Symbol(b, Decl(b.ts, 1, 8)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource18.types b/tsc/testdata/baselines/reference/conformance/importSource18.types new file mode 100644 index 0000000000000..3c4781100c5e0 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource18.types @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/importSource/importSource18.ts] //// + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +import { b } from "./a.wasm"; +>b : any + +const c: WebAssembly.Module = a; +>c : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +b; +>b : any + diff --git a/tsc/testdata/baselines/reference/conformance/importSource19.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource19.errors.txt new file mode 100644 index 0000000000000..abb4e3c4275f2 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource19.errors.txt @@ -0,0 +1,15 @@ +a.ts(1,22): error TS2307: Cannot find module './missing.wasm' or its corresponding type declarations. +a.ts(2,25): error TS2307: Cannot find module './missing.wasm' or its corresponding type declarations. + + +==== a.ts (2 errors) ==== + import source a from "./missing.wasm"; + ~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './missing.wasm' or its corresponding type declarations. + const b = import.source("./missing.wasm"); + ~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './missing.wasm' or its corresponding type declarations. + + a; + b; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource19.js b/tsc/testdata/baselines/reference/conformance/importSource19.js new file mode 100644 index 0000000000000..7ef574ec0d495 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource19.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/importSource/importSource19.ts] //// + +//// [a.ts] +import source a from "./missing.wasm"; +const b = import.source("./missing.wasm"); + +a; +b; + + +//// [a.js] +import source a from "./missing.wasm"; +const b = import.source("./missing.wasm"); +a; +b; diff --git a/tsc/testdata/baselines/reference/conformance/importSource19.symbols b/tsc/testdata/baselines/reference/conformance/importSource19.symbols new file mode 100644 index 0000000000000..bdfd6502c0ad4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource19.symbols @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/importSource/importSource19.ts] //// + +=== a.ts === +import source a from "./missing.wasm"; +>a : Symbol(a, Decl(a.ts, 0, 6)) + +const b = import.source("./missing.wasm"); +>b : Symbol(b, Decl(a.ts, 1, 5)) + +a; +>a : Symbol(a, Decl(a.ts, 0, 6)) + +b; +>b : Symbol(b, Decl(a.ts, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource19.types b/tsc/testdata/baselines/reference/conformance/importSource19.types new file mode 100644 index 0000000000000..b13a2424c23a6 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource19.types @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource19.ts] //// + +=== a.ts === +import source a from "./missing.wasm"; +>a : any + +const b = import.source("./missing.wasm"); +>b : Promise +>import.source("./missing.wasm") : Promise +>source : any +>"./missing.wasm" : "./missing.wasm" + +a; +>a : any + +b; +>b : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).js b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).js new file mode 100644 index 0000000000000..60aa74726e50e --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +export {}; +const a = import.source("./a.wasm"); +const b: Promise = a; + +//// [c.ts] +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +const b: Promise = a; + +//// [d.ts] +export {}; +const a = import.source("./a.wasm",); +const b: Promise = a; +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +const d: Promise = c; + +//// [e.ts] +export {}; +const a = import.source(`./a.wasm`); +const b: Promise = a; + + +//// [b.js] +const a = import.source("./a.wasm"); +const b = a; +export {}; +//// [c.js] +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +const b = a; +export {}; +//// [d.js] +const a = import.source("./a.wasm"); +const b = a; +const c = import.source("./a.wasm", { with: { type: "webassembly" } }); +const d = c; +export {}; +//// [e.js] +const a = import.source(`./a.wasm`); +const b = a; +export {}; diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).symbols b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).symbols new file mode 100644 index 0000000000000..f7e38f965b06a --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).symbols @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +export {}; +const a = import.source("./a.wasm"); +>a : Symbol(a, Decl(b.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(b.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 1, 5)) + +=== c.ts === +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +>a : Symbol(a, Decl(c.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) +>with : Symbol(with, Decl(c.ts, 1, 37)) +>type : Symbol(type, Decl(c.ts, 1, 45)) + +const b: Promise = a; +>b : Symbol(b, Decl(c.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 1, 5)) + +=== d.ts === +export {}; +const a = import.source("./a.wasm",); +>a : Symbol(a, Decl(d.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(d.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(d.ts, 1, 5)) + +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +>c : Symbol(c, Decl(d.ts, 3, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) +>with : Symbol(with, Decl(d.ts, 3, 37)) +>type : Symbol(type, Decl(d.ts, 3, 45)) + +const d: Promise = c; +>d : Symbol(d, Decl(d.ts, 4, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>c : Symbol(c, Decl(d.ts, 3, 5)) + +=== e.ts === +export {}; +const a = import.source(`./a.wasm`); +>a : Symbol(a, Decl(e.ts, 1, 5)) +>`./a.wasm` : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(e.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(e.ts, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).types b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).types new file mode 100644 index 0000000000000..de63cfce0c9bd --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=esnext).types @@ -0,0 +1,79 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +export {}; +const a = import.source("./a.wasm"); +>a : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +=== c.ts === +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +>a : Promise +>import.source("./a.wasm", { with: { type: "webassembly" } }) : Promise +>source : any +>"./a.wasm" : "./a.wasm" +>{ with: { type: "webassembly" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "webassembly" } : { type: string; } +>type : string +>"webassembly" : "webassembly" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +=== d.ts === +export {}; +const a = import.source("./a.wasm",); +>a : Promise +>import.source("./a.wasm",) : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +>c : Promise +>import.source("./a.wasm", { with: { type: "webassembly" } },) : Promise +>source : any +>"./a.wasm" : "./a.wasm" +>{ with: { type: "webassembly" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "webassembly" } : { type: string; } +>type : string +>"webassembly" : "webassembly" + +const d: Promise = c; +>d : Promise +>WebAssembly : any +>c : Promise + +=== e.ts === +export {}; +const a = import.source(`./a.wasm`); +>a : Promise +>import.source(`./a.wasm`) : Promise +>source : any +>`./a.wasm` : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).js b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).js new file mode 100644 index 0000000000000..02d3aed49a88c --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +export {}; +const a = import.source("./a.wasm"); +const b: Promise = a; + +//// [c.ts] +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +const b: Promise = a; + +//// [d.ts] +export {}; +const a = import.source("./a.wasm",); +const b: Promise = a; +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +const d: Promise = c; + +//// [e.ts] +export {}; +const a = import.source(`./a.wasm`); +const b: Promise = a; + + +//// [b.js] +const a = import.source("./a.wasm"); +const b = a; +//// [c.js] +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +const b = a; +//// [d.js] +const a = import.source("./a.wasm"); +const b = a; +const c = import.source("./a.wasm", { with: { type: "webassembly" } }); +const d = c; +//// [e.js] +const a = import.source(`./a.wasm`); +const b = a; diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).symbols b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).symbols new file mode 100644 index 0000000000000..f7e38f965b06a --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).symbols @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +export {}; +const a = import.source("./a.wasm"); +>a : Symbol(a, Decl(b.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(b.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.ts, 1, 5)) + +=== c.ts === +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +>a : Symbol(a, Decl(c.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) +>with : Symbol(with, Decl(c.ts, 1, 37)) +>type : Symbol(type, Decl(c.ts, 1, 45)) + +const b: Promise = a; +>b : Symbol(b, Decl(c.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.ts, 1, 5)) + +=== d.ts === +export {}; +const a = import.source("./a.wasm",); +>a : Symbol(a, Decl(d.ts, 1, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(d.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(d.ts, 1, 5)) + +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +>c : Symbol(c, Decl(d.ts, 3, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) +>with : Symbol(with, Decl(d.ts, 3, 37)) +>type : Symbol(type, Decl(d.ts, 3, 45)) + +const d: Promise = c; +>d : Symbol(d, Decl(d.ts, 4, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>c : Symbol(c, Decl(d.ts, 3, 5)) + +=== e.ts === +export {}; +const a = import.source(`./a.wasm`); +>a : Symbol(a, Decl(e.ts, 1, 5)) +>`./a.wasm` : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +const b: Promise = a; +>b : Symbol(b, Decl(e.ts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(e.ts, 1, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).types b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).types new file mode 100644 index 0000000000000..de63cfce0c9bd --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource2(module=preserve).types @@ -0,0 +1,79 @@ +//// [tests/cases/conformance/importSource/importSource2.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +export {}; +const a = import.source("./a.wasm"); +>a : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +=== c.ts === +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +>a : Promise +>import.source("./a.wasm", { with: { type: "webassembly" } }) : Promise +>source : any +>"./a.wasm" : "./a.wasm" +>{ with: { type: "webassembly" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "webassembly" } : { type: string; } +>type : string +>"webassembly" : "webassembly" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +=== d.ts === +export {}; +const a = import.source("./a.wasm",); +>a : Promise +>import.source("./a.wasm",) : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +>c : Promise +>import.source("./a.wasm", { with: { type: "webassembly" } },) : Promise +>source : any +>"./a.wasm" : "./a.wasm" +>{ with: { type: "webassembly" } } : { with: { type: string; }; } +>with : { type: string; } +>{ type: "webassembly" } : { type: string; } +>type : string +>"webassembly" : "webassembly" + +const d: Promise = c; +>d : Promise +>WebAssembly : any +>c : Promise + +=== e.ts === +export {}; +const a = import.source(`./a.wasm`); +>a : Promise +>import.source(`./a.wasm`) : Promise +>source : any +>`./a.wasm` : "./a.wasm" + +const b: Promise = a; +>b : Promise +>WebAssembly : any +>a : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource20.js b/tsc/testdata/baselines/reference/conformance/importSource20.js new file mode 100644 index 0000000000000..f3053b3182ca1 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource20.js @@ -0,0 +1,28 @@ +//// [tests/cases/conformance/importSource/importSource20.ts] //// + +//// [package.json] +{"name":"a","exports":{"types":"./index.d.ts","default":"./a.wasm"}} + +//// [index.d.ts] +declare const a: string; +export default a; + +//// [a.wasm] + +//// [b.ts] +import a from "a"; +import source b from "a"; +const c: string = a; +const d: WebAssembly.Module = b; + +const e = import.source("a"); +const f: Promise = e; + + +//// [b.js] +import a from "a"; +import source b from "a"; +const c = a; +const d = b; +const e = import.source("a"); +const f = e; diff --git a/tsc/testdata/baselines/reference/conformance/importSource20.symbols b/tsc/testdata/baselines/reference/conformance/importSource20.symbols new file mode 100644 index 0000000000000..d3513a9a5d76e --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource20.symbols @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/importSource/importSource20.ts] //// + +=== b.ts === +import a from "a"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +import source b from "a"; +>b : Symbol(b, Decl(b.ts, 1, 6)) + +const c: string = a; +>c : Symbol(c, Decl(b.ts, 2, 5)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const d: WebAssembly.Module = b; +>d : Symbol(d, Decl(b.ts, 3, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>b : Symbol(b, Decl(b.ts, 1, 6)) + +const e = import.source("a"); +>e : Symbol(e, Decl(b.ts, 5, 5)) + +const f: Promise = e; +>f : Symbol(f, Decl(b.ts, 6, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>e : Symbol(e, Decl(b.ts, 5, 5)) + +=== node_modules/a/index.d.ts === +declare const a: string; +>a : Symbol(a, Decl(index.d.ts, 0, 13)) + +export default a; +>a : Symbol(a, Decl(index.d.ts, 0, 13)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource20.types b/tsc/testdata/baselines/reference/conformance/importSource20.types new file mode 100644 index 0000000000000..011f5fd2a18f4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource20.types @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/importSource/importSource20.ts] //// + +=== b.ts === +import a from "a"; +>a : string + +import source b from "a"; +>b : WebAssembly.Module + +const c: string = a; +>c : string +>a : string + +const d: WebAssembly.Module = b; +>d : WebAssembly.Module +>WebAssembly : any +>b : WebAssembly.Module + +const e = import.source("a"); +>e : Promise +>import.source("a") : Promise +>source : any +>"a" : "a" + +const f: Promise = e; +>f : Promise +>WebAssembly : any +>e : Promise + +=== node_modules/a/index.d.ts === +declare const a: string; +>a : string + +export default a; +>a : string + diff --git a/tsc/testdata/baselines/reference/conformance/importSource21.js b/tsc/testdata/baselines/reference/conformance/importSource21.js new file mode 100644 index 0000000000000..a928bd8fc77a9 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource21.js @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/importSource/importSource21.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.wasm"; +export { a }; + +//// [c.ts] +import source a from "././a.wasm"; +export { a }; + +//// [d.ts] +export * from "./b.js"; +export * from "./c.js"; + +//// [e.wasm] + +//// [f.ts] +import source e from "./e.wasm"; +export { e }; + +//// [g.ts] +import source e from "././e.wasm"; +export { e }; + +//// [h.ts] +export * from "./f.js"; +export * from "./g.js"; + +//// [i.ts] +import { a } from "./d.js"; +import { e } from "./h.js"; +const b: WebAssembly.Module = a; +const c: WebAssembly.Module = e; + + +//// [b.js] +import source a from "./a.wasm"; +export { a }; +//// [c.js] +import source a from "././a.wasm"; +export { a }; +//// [d.js] +export * from "./b.js"; +export * from "./c.js"; +//// [f.js] +import source e from "./e.wasm"; +export { e }; +//// [g.js] +import source e from "././e.wasm"; +export { e }; +//// [h.js] +export * from "./f.js"; +export * from "./g.js"; +//// [i.js] +import { a } from "./d.js"; +import { e } from "./h.js"; +const b = a; +const c = e; diff --git a/tsc/testdata/baselines/reference/conformance/importSource21.symbols b/tsc/testdata/baselines/reference/conformance/importSource21.symbols new file mode 100644 index 0000000000000..82401d8a7e72b --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource21.symbols @@ -0,0 +1,59 @@ +//// [tests/cases/conformance/importSource/importSource21.ts] //// + +=== i.ts === +import { a } from "./d.js"; +>a : Symbol(a, Decl(i.ts, 0, 8)) + +import { e } from "./h.js"; +>e : Symbol(e, Decl(i.ts, 1, 8)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(i.ts, 2, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(i.ts, 0, 8)) + +const c: WebAssembly.Module = e; +>c : Symbol(c, Decl(i.ts, 3, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>e : Symbol(e, Decl(i.ts, 1, 8)) + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export { a }; +>a : Symbol(a, Decl(b.ts, 1, 8)) + +=== c.ts === +import source a from "././a.wasm"; +>a : Symbol(a, Decl(c.ts, 0, 6)) + +export { a }; +>a : Symbol(a, Decl(c.ts, 1, 8)) + +=== d.ts === + +export * from "./b.js"; +export * from "./c.js"; + +=== f.ts === +import source e from "./e.wasm"; +>e : Symbol(e, Decl(f.ts, 0, 6)) + +export { e }; +>e : Symbol(e, Decl(f.ts, 1, 8)) + +=== g.ts === +import source e from "././e.wasm"; +>e : Symbol(e, Decl(g.ts, 0, 6)) + +export { e }; +>e : Symbol(e, Decl(g.ts, 1, 8)) + +=== h.ts === + +export * from "./f.js"; +export * from "./g.js"; + diff --git a/tsc/testdata/baselines/reference/conformance/importSource21.types b/tsc/testdata/baselines/reference/conformance/importSource21.types new file mode 100644 index 0000000000000..163d8201a344a --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource21.types @@ -0,0 +1,57 @@ +//// [tests/cases/conformance/importSource/importSource21.ts] //// + +=== i.ts === +import { a } from "./d.js"; +>a : WebAssembly.Module + +import { e } from "./h.js"; +>e : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +const c: WebAssembly.Module = e; +>c : WebAssembly.Module +>WebAssembly : any +>e : WebAssembly.Module + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +export { a }; +>a : WebAssembly.Module + +=== c.ts === +import source a from "././a.wasm"; +>a : WebAssembly.Module + +export { a }; +>a : WebAssembly.Module + +=== d.ts === + +export * from "./b.js"; +export * from "./c.js"; + +=== f.ts === +import source e from "./e.wasm"; +>e : WebAssembly.Module + +export { e }; +>e : WebAssembly.Module + +=== g.ts === +import source e from "././e.wasm"; +>e : WebAssembly.Module + +export { e }; +>e : WebAssembly.Module + +=== h.ts === + +export * from "./f.js"; +export * from "./g.js"; + diff --git a/tsc/testdata/baselines/reference/conformance/importSource22.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource22.errors.txt new file mode 100644 index 0000000000000..6d0b034cb5179 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource22.errors.txt @@ -0,0 +1,18 @@ +c.cts(1,8): error TS100074: Source phase imports are not allowed on statements that compile to CommonJS 'require' calls. + + +==== a.d.wasm.ts (0 errors) ==== + export {}; + +==== b.mts (0 errors) ==== + import source a from "./a.wasm"; + const b: WebAssembly.Module = a; + const c: Promise = import.source("./a.wasm"); + +==== c.cts (1 errors) ==== + import source a from "./a.wasm"; + ~~~~~~~~ +!!! error TS100074: Source phase imports are not allowed on statements that compile to CommonJS 'require' calls. + const b: WebAssembly.Module = a; + const c: Promise = import.source("./a.wasm"); + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource22.js b/tsc/testdata/baselines/reference/conformance/importSource22.js new file mode 100644 index 0000000000000..184e4151da322 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource22.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/importSource/importSource22.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.mts] +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +const c: Promise = import.source("./a.wasm"); + +//// [c.cts] +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +const c: Promise = import.source("./a.wasm"); + + +//// [b.mjs] +import source a from "./a.wasm"; +const b = a; +const c = import.source("./a.wasm"); +//// [c.cjs] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const a_wasm_1 = __importDefault(require("./a.wasm")); +const b = a_wasm_1.default; +const c = import.source("./a.wasm"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource22.symbols b/tsc/testdata/baselines/reference/conformance/importSource22.symbols new file mode 100644 index 0000000000000..40581deeec161 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource22.symbols @@ -0,0 +1,40 @@ +//// [tests/cases/conformance/importSource/importSource22.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.mts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.mts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(b.mts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(b.mts, 0, 6)) + +const c: Promise = import.source("./a.wasm"); +>c : Symbol(c, Decl(b.mts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + +=== c.cts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(c.cts, 0, 6)) + +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(c.cts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(c.cts, 0, 6)) + +const c: Promise = import.source("./a.wasm"); +>c : Symbol(c, Decl(c.cts, 2, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource22.types b/tsc/testdata/baselines/reference/conformance/importSource22.types new file mode 100644 index 0000000000000..b998860a6e989 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource22.types @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/importSource/importSource22.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.mts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +const c: Promise = import.source("./a.wasm"); +>c : Promise +>WebAssembly : any +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + +=== c.cts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + +const c: Promise = import.source("./a.wasm"); +>c : Promise +>WebAssembly : any +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource23.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource23.errors.txt new file mode 100644 index 0000000000000..179eab3caf41b --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource23.errors.txt @@ -0,0 +1,16 @@ +b.ts(1,22): error TS100075: A declaration file cannot be imported with a source phase import. +b.ts(3,15): error TS100075: A declaration file cannot be imported with a source phase import. + + +==== a.d.wasm.ts (0 errors) ==== + export {}; + +==== b.ts (2 errors) ==== + import source a from "./a.d.wasm.ts"; + ~~~~~~~~~~~~~~~ +!!! error TS100075: A declaration file cannot be imported with a source phase import. + a; + import.source("./a.d.wasm.ts"); + ~~~~~~~~~~~~~~~ +!!! error TS100075: A declaration file cannot be imported with a source phase import. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource23.js b/tsc/testdata/baselines/reference/conformance/importSource23.js new file mode 100644 index 0000000000000..df743c2d9ca71 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource23.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/importSource/importSource23.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.d.wasm.ts"; +a; +import.source("./a.d.wasm.ts"); + + +//// [b.js] +import source a from "./a.d.wasm.ts"; +a; +import.source("./a.d.wasm.ts"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource23.symbols b/tsc/testdata/baselines/reference/conformance/importSource23.symbols new file mode 100644 index 0000000000000..885a8a5639f46 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource23.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importSource/importSource23.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.d.wasm.ts"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +a; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +import.source("./a.d.wasm.ts"); +>"./a.d.wasm.ts" : Symbol("./a.d.wasm.ts", Decl(a.d.wasm.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource23.types b/tsc/testdata/baselines/reference/conformance/importSource23.types new file mode 100644 index 0000000000000..20f17ebcff43a --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource23.types @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource23.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.d.wasm.ts"; +>a : WebAssembly.Module + +a; +>a : WebAssembly.Module + +import.source("./a.d.wasm.ts"); +>import.source("./a.d.wasm.ts") : Promise +>source : any +>"./a.d.wasm.ts" : "./a.d.wasm.ts" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource24.js b/tsc/testdata/baselines/reference/conformance/importSource24.js new file mode 100644 index 0000000000000..0d1654a35dbdf --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource24.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource24.ts] //// + +//// [package.json] +{"type":"commonjs"} + +//// [a.ts] +export {}; + +//// [b.cts] +export const a = import.source("./a.ts"); + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [b.cjs] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = import.source("./a.js"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource24.symbols b/tsc/testdata/baselines/reference/conformance/importSource24.symbols new file mode 100644 index 0000000000000..fd24d19a7c478 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource24.symbols @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/importSource/importSource24.ts] //// + +=== a.ts === + +export {}; + +=== b.cts === +export const a = import.source("./a.ts"); +>a : Symbol(a, Decl(b.cts, 0, 12)) +>"./a.ts" : Symbol("./a", Decl(a.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource24.types b/tsc/testdata/baselines/reference/conformance/importSource24.types new file mode 100644 index 0000000000000..1a2726ea39aa0 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource24.types @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/importSource/importSource24.ts] //// + +=== a.ts === + +export {}; + +=== b.cts === +export const a = import.source("./a.ts"); +>a : Promise +>import.source("./a.ts") : Promise +>source : any +>"./a.ts" : "./a.ts" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource25.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource25.errors.txt new file mode 100644 index 0000000000000..52eb3bc4d355a --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource25.errors.txt @@ -0,0 +1,36 @@ +g.ts(2,1): error TS2308: Module "./b.js" has already exported a member named 'value'. Consider explicitly re-exporting to resolve the ambiguity. + + +==== a.d.ts (0 errors) ==== + declare module "*.txt"; + +==== b.ts (0 errors) ==== + import source a from "./a.txt"; + export { a as value }; + +==== c.ts (0 errors) ==== + import source a from "././a.txt"; + export { a as value }; + +==== d.ts (0 errors) ==== + export * from "./b.js"; + export * from "./c.js"; + +==== e.ts (0 errors) ==== + import { value } from "./d.js"; + value; + +==== f.ts (0 errors) ==== + import source a from "./b.txt"; + export { a as value }; + +==== g.ts (1 errors) ==== + export * from "./b.js"; + export * from "./f.js"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2308: Module "./b.js" has already exported a member named 'value'. Consider explicitly re-exporting to resolve the ambiguity. + +==== h.ts (0 errors) ==== + import { value } from "./g.js"; + value; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource25.js b/tsc/testdata/baselines/reference/conformance/importSource25.js new file mode 100644 index 0000000000000..8053d2177fd3c --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource25.js @@ -0,0 +1,55 @@ +//// [tests/cases/conformance/importSource/importSource25.ts] //// + +//// [a.d.ts] +declare module "*.txt"; + +//// [b.ts] +import source a from "./a.txt"; +export { a as value }; + +//// [c.ts] +import source a from "././a.txt"; +export { a as value }; + +//// [d.ts] +export * from "./b.js"; +export * from "./c.js"; + +//// [e.ts] +import { value } from "./d.js"; +value; + +//// [f.ts] +import source a from "./b.txt"; +export { a as value }; + +//// [g.ts] +export * from "./b.js"; +export * from "./f.js"; + +//// [h.ts] +import { value } from "./g.js"; +value; + + +//// [b.js] +import source a from "./a.txt"; +export { a as value }; +//// [c.js] +import source a from "././a.txt"; +export { a as value }; +//// [d.js] +export * from "./b.js"; +export * from "./c.js"; +//// [e.js] +import { value } from "./d.js"; +value; +//// [f.js] +import source a from "./b.txt"; +export { a as value }; +//// [g.js] +export * from "./b.js"; +export * from "./f.js"; +//// [h.js] +import { value } from "./g.js"; +value; diff --git a/tsc/testdata/baselines/reference/conformance/importSource25.symbols b/tsc/testdata/baselines/reference/conformance/importSource25.symbols new file mode 100644 index 0000000000000..b6765472d7a76 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource25.symbols @@ -0,0 +1,54 @@ +//// [tests/cases/conformance/importSource/importSource25.ts] //// + +=== a.d.ts === +declare module "*.txt"; +>"*.txt" : Symbol("*.txt", Decl(a.d.ts, 0, 0)) + +=== b.ts === +import source a from "./a.txt"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export { a as value }; +>a : Symbol(a, Decl(b.ts, 0, 6)) +>value : Symbol(value, Decl(b.ts, 1, 8)) + +=== c.ts === +import source a from "././a.txt"; +>a : Symbol(a, Decl(c.ts, 0, 6)) + +export { a as value }; +>a : Symbol(a, Decl(c.ts, 0, 6)) +>value : Symbol(value, Decl(c.ts, 1, 8)) + +=== d.ts === + +export * from "./b.js"; +export * from "./c.js"; + +=== e.ts === +import { value } from "./d.js"; +>value : Symbol(value, Decl(e.ts, 0, 8)) + +value; +>value : Symbol(value, Decl(e.ts, 0, 8)) + +=== f.ts === +import source a from "./b.txt"; +>a : Symbol(a, Decl(f.ts, 0, 6)) + +export { a as value }; +>a : Symbol(a, Decl(f.ts, 0, 6)) +>value : Symbol(value, Decl(f.ts, 1, 8)) + +=== g.ts === + +export * from "./b.js"; +export * from "./f.js"; + +=== h.ts === +import { value } from "./g.js"; +>value : Symbol(value, Decl(h.ts, 0, 8)) + +value; +>value : Symbol(value, Decl(h.ts, 0, 8)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource25.types b/tsc/testdata/baselines/reference/conformance/importSource25.types new file mode 100644 index 0000000000000..3af37312d5ec1 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource25.types @@ -0,0 +1,54 @@ +//// [tests/cases/conformance/importSource/importSource25.ts] //// + +=== a.d.ts === +declare module "*.txt"; +>"*.txt" : any + +=== b.ts === +import source a from "./a.txt"; +>a : any + +export { a as value }; +>a : any +>value : any + +=== c.ts === +import source a from "././a.txt"; +>a : any + +export { a as value }; +>a : any +>value : any + +=== d.ts === + +export * from "./b.js"; +export * from "./c.js"; + +=== e.ts === +import { value } from "./d.js"; +>value : any + +value; +>value : any + +=== f.ts === +import source a from "./b.txt"; +>a : any + +export { a as value }; +>a : any +>value : any + +=== g.ts === + +export * from "./b.js"; +export * from "./f.js"; + +=== h.ts === +import { value } from "./g.js"; +>value : any + +value; +>value : any + diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).errors.txt b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).errors.txt new file mode 100644 index 0000000000000..f30b6499ac930 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).errors.txt @@ -0,0 +1,18 @@ +b.js(1,8): error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. +b.js(2,11): error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + + +==== package.json (0 errors) ==== + {"type":"commonjs"} + +==== a.js (0 errors) ==== + export default 1; + +==== b.js (2 errors) ==== + import source a from "./a.js"; + ~~~~~~~~ +!!! error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + const b = import.source("./a.js"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).symbols b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).symbols new file mode 100644 index 0000000000000..468809120f3a8 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).symbols @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/importSource/importSource26.ts] //// + +=== a.js === + +export default 1; + +=== b.js === +import source a from "./a.js"; +>a : Symbol(a, Decl(b.js, 0, 6)) + +const b = import.source("./a.js"); +>b : Symbol(b, Decl(b.js, 1, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).types b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).types new file mode 100644 index 0000000000000..2dec247dd5fa4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=commonjs).types @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importSource/importSource26.ts] //// + +=== a.js === + +export default 1; + +=== b.js === +import source a from "./a.js"; +>a : any + +const b = import.source("./a.js"); +>b : Promise +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).errors.txt b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).errors.txt new file mode 100644 index 0000000000000..b62f363d3141d --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).errors.txt @@ -0,0 +1,15 @@ +b.js(1,8): error TS100074: Source phase imports are not allowed on statements that compile to CommonJS 'require' calls. + + +==== package.json (0 errors) ==== + {"type":"commonjs"} + +==== a.js (0 errors) ==== + export default 1; + +==== b.js (1 errors) ==== + import source a from "./a.js"; + ~~~~~~~~ +!!! error TS100074: Source phase imports are not allowed on statements that compile to CommonJS 'require' calls. + const b = import.source("./a.js"); + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).symbols b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).symbols new file mode 100644 index 0000000000000..468809120f3a8 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).symbols @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/importSource/importSource26.ts] //// + +=== a.js === + +export default 1; + +=== b.js === +import source a from "./a.js"; +>a : Symbol(a, Decl(b.js, 0, 6)) + +const b = import.source("./a.js"); +>b : Symbol(b, Decl(b.js, 1, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.js, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).types b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).types new file mode 100644 index 0000000000000..2dec247dd5fa4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource26(module=nodenext).types @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importSource/importSource26.ts] //// + +=== a.js === + +export default 1; + +=== b.js === +import source a from "./a.js"; +>a : any + +const b = import.source("./a.js"); +>b : Promise +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource27.symbols b/tsc/testdata/baselines/reference/conformance/importSource27.symbols new file mode 100644 index 0000000000000..e68d2173c54c7 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource27.symbols @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/importSource/importSource27.ts] //// + +=== e.ts === +import source a from "./a.js"; +>a : Symbol(a, Decl(e.ts, 0, 6)) + +import source b from "./b.mjs"; +>b : Symbol(b, Decl(e.ts, 1, 6)) + +import source c from "./c.cjs"; +>c : Symbol(c, Decl(e.ts, 2, 6)) + +import source d from "./d.jsx"; +>d : Symbol(d, Decl(e.ts, 3, 6)) + +const e = import.source("./a.js"); +>e : Symbol(e, Decl(e.ts, 4, 5)) + +const f: any = a; +>f : Symbol(f, Decl(e.ts, 6, 5)) +>a : Symbol(a, Decl(e.ts, 0, 6)) + +const g: any = b; +>g : Symbol(g, Decl(e.ts, 7, 5)) +>b : Symbol(b, Decl(e.ts, 1, 6)) + +const h: any = c; +>h : Symbol(h, Decl(e.ts, 8, 5)) +>c : Symbol(c, Decl(e.ts, 2, 6)) + +const i: any = d; +>i : Symbol(i, Decl(e.ts, 9, 5)) +>d : Symbol(d, Decl(e.ts, 3, 6)) + +const j: Promise = e; +>j : Symbol(j, Decl(e.ts, 10, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>e : Symbol(e, Decl(e.ts, 4, 5)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource27.types b/tsc/testdata/baselines/reference/conformance/importSource27.types new file mode 100644 index 0000000000000..2892c78851ba1 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource27.types @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/importSource/importSource27.ts] //// + +=== e.ts === +import source a from "./a.js"; +>a : any + +import source b from "./b.mjs"; +>b : any + +import source c from "./c.cjs"; +>c : any + +import source d from "./d.jsx"; +>d : any + +const e = import.source("./a.js"); +>e : Promise +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +const f: any = a; +>f : any +>a : any + +const g: any = b; +>g : any +>b : any + +const h: any = c; +>h : any +>c : any + +const i: any = d; +>i : any +>d : any + +const j: Promise = e; +>j : Promise +>e : Promise + diff --git a/tsc/testdata/baselines/reference/conformance/importSource3.js b/tsc/testdata/baselines/reference/conformance/importSource3.js new file mode 100644 index 0000000000000..23db38f2a5f9e --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource3.js @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/importSource/importSource3.ts] //// + +//// [a.ts] +export default 1; +export const a = 2; + +//// [b.ts] +import source from "./a.js"; +const a: number = source; + +//// [c.ts] +import source, { a } from "./a.js"; +const b: number = source + a; + +//// [d.ts] +import source = require("./a"); +const a: typeof source = source; + +//// [e.ts] +const source = 1; +const a: number = source; + +//// [f.d.wasm.ts] +export {}; + +//// [g.ts] +import source from from "./f.wasm"; +const a: WebAssembly.Module = from; + +//// [h.ts] +import source type from "./f.wasm"; +const a: WebAssembly.Module = type; + +//// [i.ts] +import source source from "./f.wasm"; +const a: WebAssembly.Module = source; + +//// [j.ts] +import +source +a +from "./f.wasm"; +const b: WebAssembly.Module = a; + + +//// [a.js] +export default 1; +export const a = 2; +//// [b.js] +import source from "./a.js"; +const a = source; +//// [c.js] +import source, { a } from "./a.js"; +const b = source + a; +//// [d.js] +const source = require("./a"); +const a = source; +//// [e.js] +"use strict"; +const source = 1; +const a = source; +//// [g.js] +import source from from "./f.wasm"; +const a = from; +//// [h.js] +import source type from "./f.wasm"; +const a = type; +//// [i.js] +import source source from "./f.wasm"; +const a = source; +//// [j.js] +import source a from "./f.wasm"; +const b = a; diff --git a/tsc/testdata/baselines/reference/conformance/importSource3.symbols b/tsc/testdata/baselines/reference/conformance/importSource3.symbols new file mode 100644 index 0000000000000..244a1e44c03a8 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource3.symbols @@ -0,0 +1,89 @@ +//// [tests/cases/conformance/importSource/importSource3.ts] //// + +=== a.ts === +export default 1; +export const a = 2; +>a : Symbol(a, Decl(a.ts, 1, 12)) + +=== b.ts === +import source from "./a.js"; +>source : Symbol(source, Decl(b.ts, 0, 6)) + +const a: number = source; +>a : Symbol(a, Decl(b.ts, 1, 5)) +>source : Symbol(source, Decl(b.ts, 0, 6)) + +=== c.ts === +import source, { a } from "./a.js"; +>source : Symbol(source, Decl(c.ts, 0, 6)) +>a : Symbol(a, Decl(c.ts, 0, 16)) + +const b: number = source + a; +>b : Symbol(b, Decl(c.ts, 1, 5)) +>source : Symbol(source, Decl(c.ts, 0, 6)) +>a : Symbol(a, Decl(c.ts, 0, 16)) + +=== d.ts === +import source = require("./a"); +>source : Symbol(source, Decl(d.ts, 0, 0)) + +const a: typeof source = source; +>a : Symbol(a, Decl(d.ts, 1, 5)) +>source : Symbol(source, Decl(d.ts, 0, 0)) +>source : Symbol(source, Decl(d.ts, 0, 0)) + +=== e.ts === +const source = 1; +>source : Symbol(source, Decl(e.ts, 0, 5)) + +const a: number = source; +>a : Symbol(a, Decl(e.ts, 1, 5)) +>source : Symbol(source, Decl(e.ts, 0, 5)) + +=== f.d.wasm.ts === + +export {}; + +=== g.ts === +import source from from "./f.wasm"; +>from : Symbol(from, Decl(g.ts, 0, 6)) + +const a: WebAssembly.Module = from; +>a : Symbol(a, Decl(g.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>from : Symbol(from, Decl(g.ts, 0, 6)) + +=== h.ts === +import source type from "./f.wasm"; +>type : Symbol(type, Decl(h.ts, 0, 6)) + +const a: WebAssembly.Module = type; +>a : Symbol(a, Decl(h.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>type : Symbol(type, Decl(h.ts, 0, 6)) + +=== i.ts === +import source source from "./f.wasm"; +>source : Symbol(source, Decl(i.ts, 0, 6)) + +const a: WebAssembly.Module = source; +>a : Symbol(a, Decl(i.ts, 1, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>source : Symbol(source, Decl(i.ts, 0, 6)) + +=== j.ts === +import +source +a +>a : Symbol(a, Decl(j.ts, 0, 6)) + +from "./f.wasm"; +const b: WebAssembly.Module = a; +>b : Symbol(b, Decl(j.ts, 4, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>a : Symbol(a, Decl(j.ts, 0, 6)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource3.types b/tsc/testdata/baselines/reference/conformance/importSource3.types new file mode 100644 index 0000000000000..c371ea99151d4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource3.types @@ -0,0 +1,88 @@ +//// [tests/cases/conformance/importSource/importSource3.ts] //// + +=== a.ts === +export default 1; +export const a = 2; +>a : 2 +>2 : 2 + +=== b.ts === +import source from "./a.js"; +>source : 1 + +const a: number = source; +>a : number +>source : 1 + +=== c.ts === +import source, { a } from "./a.js"; +>source : 1 +>a : 2 + +const b: number = source + a; +>b : number +>source + a : number +>source : 1 +>a : 2 + +=== d.ts === +import source = require("./a"); +>source : typeof source + +const a: typeof source = source; +>a : typeof source +>source : typeof source +>source : typeof source + +=== e.ts === +const source = 1; +>source : 1 +>1 : 1 + +const a: number = source; +>a : number +>source : 1 + +=== f.d.wasm.ts === + +export {}; + +=== g.ts === +import source from from "./f.wasm"; +>from : WebAssembly.Module + +const a: WebAssembly.Module = from; +>a : WebAssembly.Module +>WebAssembly : any +>from : WebAssembly.Module + +=== h.ts === +import source type from "./f.wasm"; +>type : WebAssembly.Module + +const a: WebAssembly.Module = type; +>a : WebAssembly.Module +>WebAssembly : any +>type : WebAssembly.Module + +=== i.ts === +import source source from "./f.wasm"; +>source : WebAssembly.Module + +const a: WebAssembly.Module = source; +>a : WebAssembly.Module +>WebAssembly : any +>source : WebAssembly.Module + +=== j.ts === +import +source +a +>a : WebAssembly.Module + +from "./f.wasm"; +const b: WebAssembly.Module = a; +>b : WebAssembly.Module +>WebAssembly : any +>a : WebAssembly.Module + diff --git a/tsc/testdata/baselines/reference/conformance/importSource4.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource4.errors.txt new file mode 100644 index 0000000000000..3e64f632ed3ab --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource4.errors.txt @@ -0,0 +1,45 @@ +b.ts(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +c.ts(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +d.ts(1,8): error TS100070: Named and namespace imports are not allowed in a source phase import. +e.ts(1,8): error TS100069: A source phase import must specify a local binding. +f.ts(1,20): error TS1005: 'from' expected. +f.ts(1,20): error TS1141: String literal expected. +f.ts(1,22): error TS1005: ';' expected. +f.ts(1,22): error TS2304: Cannot find name 'from'. + + +==== a.ts (0 errors) ==== + export default 1; + export const a = 2; + +==== b.ts (1 errors) ==== + import source * as a from "./a.js"; + ~~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== c.ts (1 errors) ==== + import source { a } from "./a.js"; + ~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== d.ts (1 errors) ==== + import source a, { a as b } from "./a.js"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS100070: Named and namespace imports are not allowed in a source phase import. + +==== e.ts (1 errors) ==== + import source "./a.js"; + ~~~~~~ +!!! error TS100069: A source phase import must specify a local binding. + +==== f.ts (4 errors) ==== + import source type a from "./a.js"; + ~ +!!! error TS1005: 'from' expected. + ~ +!!! error TS1141: String literal expected. + ~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource4.js b/tsc/testdata/baselines/reference/conformance/importSource4.js new file mode 100644 index 0000000000000..236ebcde632d8 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource4.js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/importSource/importSource4.ts] //// + +//// [a.ts] +export default 1; +export const a = 2; + +//// [b.ts] +import source * as a from "./a.js"; + +//// [c.ts] +import source { a } from "./a.js"; + +//// [d.ts] +import source a, { a as b } from "./a.js"; + +//// [e.ts] +import source "./a.js"; + +//// [f.ts] +import source type a from "./a.js"; + + +//// [a.js] +export default 1; +export const a = 2; +//// [b.js] +export {}; +//// [c.js] +export {}; +//// [d.js] +export {}; +//// [e.js] +export {}; +//// [f.js] +from; +"./a.js"; +export {}; diff --git a/tsc/testdata/baselines/reference/conformance/importSource4.symbols b/tsc/testdata/baselines/reference/conformance/importSource4.symbols new file mode 100644 index 0000000000000..1dabc24bc750e --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource4.symbols @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/importSource/importSource4.ts] //// + +=== a.ts === +export default 1; +export const a = 2; +>a : Symbol(a, Decl(a.ts, 1, 12)) + +=== b.ts === +import source * as a from "./a.js"; +>a : Symbol(a, Decl(b.ts, 0, 13)) + +=== c.ts === +import source { a } from "./a.js"; +>a : Symbol(a, Decl(c.ts, 0, 15)) + +=== d.ts === +import source a, { a as b } from "./a.js"; +>a : Symbol(a, Decl(d.ts, 0, 6)) +>a : Symbol(b, Decl(a.ts, 1, 12)) +>b : Symbol(b, Decl(d.ts, 0, 18)) + +=== e.ts === + +import source "./a.js"; + +=== f.ts === +import source type a from "./a.js"; +>type : Symbol(type, Decl(f.ts, 0, 6)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource4.types b/tsc/testdata/baselines/reference/conformance/importSource4.types new file mode 100644 index 0000000000000..d1b9942f445f6 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource4.types @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/importSource/importSource4.ts] //// + +=== a.ts === +export default 1; +export const a = 2; +>a : 2 +>2 : 2 + +=== b.ts === +import source * as a from "./a.js"; +>a : typeof a + +=== c.ts === +import source { a } from "./a.js"; +>a : 2 + +=== d.ts === +import source a, { a as b } from "./a.js"; +>a : any +>a : 2 +>b : 2 + +=== e.ts === + +import source "./a.js"; + +=== f.ts === +import source type a from "./a.js"; +>type : any +>a : any +>from : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource5.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource5.errors.txt new file mode 100644 index 0000000000000..bf7b11adc8605 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource5.errors.txt @@ -0,0 +1,71 @@ +b.ts(1,14): error TS1005: '(' expected. +b.ts(2,15): error TS1005: '(' expected. +b.ts(3,23): error TS1005: '(' expected. +b.ts(4,14): error TS1005: '(' expected. +b.ts(6,1): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments +b.ts(7,1): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments +b.ts(8,14): error TS100072: Optional chaining cannot be used with 'import.source'. +b.ts(9,1): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. +b.ts(10,15): error TS1325: Argument of dynamic import cannot be spread element. +c.ts(1,5): error TS1109: Expression expected. +d.ts(1,5): error TS1109: Expression expected. +d.ts(1,29): error TS2339: Property 'a' does not exist on type 'Promise'. +e.ts(1,21): error TS1005: '(' expected. +f.ts(1,8): error TS100073: 'a' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? + + +==== a.ts (0 errors) ==== + export default 1; + +==== b.ts (9 errors) ==== + import.source; + +!!! error TS1005: '(' expected. + (import.source)("./a.js"); + +!!! error TS1005: '(' expected. + Function(import.source); + +!!! error TS1005: '(' expected. + import.source.unknown; + +!!! error TS1005: '(' expected. + + import.source(); + ~~~~~~~~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments + import.source("./a.js", {}, {}); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments + import.source?.("./a.js"); + ~~ +!!! error TS100072: Optional chaining cannot be used with 'import.source'. + import.source("./a.js"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. + import.source(...["./a.js"]); + ~~~~~~~~~~~~~ +!!! error TS1325: Argument of dynamic import cannot be spread element. + +==== c.ts (1 errors) ==== + new import.source("./a.js"); + ~~~~~~ +!!! error TS1109: Expression expected. + +==== d.ts (2 errors) ==== + new import.source("./a.js").a; + ~~~~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS2339: Property 'a' does not exist on type 'Promise'. + +==== e.ts (1 errors) ==== + typeof import.source; + +!!! error TS1005: '(' expected. + +==== f.ts (1 errors) ==== + import.a("./a.js"); + ~ +!!! error TS100073: 'a' is not a valid meta-property for keyword 'import'. Did you mean 'meta', 'defer', or 'source'? + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource5.js b/tsc/testdata/baselines/reference/conformance/importSource5.js new file mode 100644 index 0000000000000..2a4cb481a388d --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource5.js @@ -0,0 +1,57 @@ +//// [tests/cases/conformance/importSource/importSource5.ts] //// + +//// [a.ts] +export default 1; + +//// [b.ts] +import.source; +(import.source)("./a.js"); +Function(import.source); +import.source.unknown; + +import.source(); +import.source("./a.js", {}, {}); +import.source?.("./a.js"); +import.source("./a.js"); +import.source(...["./a.js"]); + +//// [c.ts] +new import.source("./a.js"); + +//// [d.ts] +new import.source("./a.js").a; + +//// [e.ts] +typeof import.source; + +//// [f.ts] +import.a("./a.js"); + + +//// [a.js] +export default 1; +//// [b.js] +"use strict"; +import.source; +(import.source)("./a.js"); +Function(import.source); +import.source.unknown; +import.source(); +import.source("./a.js", {}, {}); +import.source?.("./a.js"); +import.source("./a.js"); +import.source(...["./a.js"]); +//// [c.js] +"use strict"; +new ; +import.source("./a.js"); +//// [d.js] +"use strict"; +new ; +import.source("./a.js").a; +//// [e.js] +"use strict"; +typeof import.source; +//// [f.js] +"use strict"; +import.a("./a.js"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource5.symbols b/tsc/testdata/baselines/reference/conformance/importSource5.symbols new file mode 100644 index 0000000000000..c855fa5fdcd33 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource5.symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/importSource/importSource5.ts] //// + +=== a.ts === + +export default 1; + +=== b.ts === +import.source; +(import.source)("./a.js"); +Function(import.source); +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.decorators.d.ts, --, --)) + +import.source.unknown; + +import.source(); +import.source("./a.js", {}, {}); +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +import.source?.("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +import.source("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +import.source(...["./a.js"]); + +=== c.ts === +new import.source("./a.js"); +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +=== d.ts === +new import.source("./a.js").a; +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + +=== e.ts === + +typeof import.source; + +=== f.ts === + +import.a("./a.js"); + diff --git a/tsc/testdata/baselines/reference/conformance/importSource5.types b/tsc/testdata/baselines/reference/conformance/importSource5.types new file mode 100644 index 0000000000000..0540292f19275 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource5.types @@ -0,0 +1,89 @@ +//// [tests/cases/conformance/importSource/importSource5.ts] //// + +=== a.ts === + +export default 1; + +=== b.ts === +import.source; +>import.source : any +>source : any + +(import.source)("./a.js"); +>(import.source)("./a.js") : any +>(import.source) : any +>import.source : any +>source : any +>"./a.js" : "./a.js" + +Function(import.source); +>Function(import.source) : Function +>Function : FunctionConstructor +>import.source : any +>source : any + +import.source.unknown; +>import.source.unknown : any +>import.source : any +>source : any +>unknown : any + +import.source(); +>import.source() : Promise +>source : any + +import.source("./a.js", {}, {}); +>import.source("./a.js", {}, {}) : Promise +>source : any +>"./a.js" : "./a.js" +>{} : {} +>{} : {} + +import.source?.("./a.js"); +>import.source?.("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +import.source("./a.js"); +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +import.source(...["./a.js"]); +>import.source(...["./a.js"]) : Promise +>source : any +>...["./a.js"] : string +>["./a.js"] : [string] +>"./a.js" : "./a.js" + +=== c.ts === +new import.source("./a.js"); +>new : any +> : any +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + +=== d.ts === +new import.source("./a.js").a; +>new : any +> : any +>import.source("./a.js").a : any +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" +>a : any + +=== e.ts === +typeof import.source; +>typeof import.source : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined" +>import.source : any +>source : any + +=== f.ts === +import.a("./a.js"); +>import.a("./a.js") : any +>import.a : any +>a : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource6.errors.txt b/tsc/testdata/baselines/reference/conformance/importSource6.errors.txt new file mode 100644 index 0000000000000..eb18218584660 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource6.errors.txt @@ -0,0 +1,15 @@ +b.ts(1,8): error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. +b.ts(2,11): error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + + +==== a.ts (0 errors) ==== + export default 1; + +==== b.ts (2 errors) ==== + import source a from "./a.js"; + ~~~~~~~~ +!!! error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + const b = import.source("./a.js"); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS100071: Source phase imports are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/importSource6.js b/tsc/testdata/baselines/reference/conformance/importSource6.js new file mode 100644 index 0000000000000..b8fc0906bed90 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource6.js @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource6.ts] //// + +//// [a.ts] +export default 1; + +//// [b.ts] +import source a from "./a.js"; +const b = import.source("./a.js"); + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 1; +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const b = import.source("./a.js"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource6.symbols b/tsc/testdata/baselines/reference/conformance/importSource6.symbols new file mode 100644 index 0000000000000..9e21b1cd3be63 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource6.symbols @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/importSource/importSource6.ts] //// + +=== a.ts === + +export default 1; + +=== b.ts === +import source a from "./a.js"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +const b = import.source("./a.js"); +>b : Symbol(b, Decl(b.ts, 1, 5)) +>"./a.js" : Symbol("./a.js", Decl(a.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource6.types b/tsc/testdata/baselines/reference/conformance/importSource6.types new file mode 100644 index 0000000000000..3a6478805b7bb --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource6.types @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importSource/importSource6.ts] //// + +=== a.ts === + +export default 1; + +=== b.ts === +import source a from "./a.js"; +>a : any + +const b = import.source("./a.js"); +>b : Promise +>import.source("./a.js") : Promise +>source : any +>"./a.js" : "./a.js" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource7.js b/tsc/testdata/baselines/reference/conformance/importSource7.js new file mode 100644 index 0000000000000..33ec4a0a381cc --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource7.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importSource/importSource7.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +import source a from "./a.wasm"; +export type B = typeof a; +export const b = import.source("./a.wasm"); + + +//// [b.js] +export const b = import.source("./a.wasm"); + + +//// [b.d.ts] +import source a from "./a.wasm"; +export type B = typeof a; +export declare const b: Promise; diff --git a/tsc/testdata/baselines/reference/conformance/importSource7.symbols b/tsc/testdata/baselines/reference/conformance/importSource7.symbols new file mode 100644 index 0000000000000..238b52c222275 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource7.symbols @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource7.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export type B = typeof a; +>B : Symbol(B, Decl(b.ts, 0, 32)) +>a : Symbol(a, Decl(b.ts, 0, 6)) + +export const b = import.source("./a.wasm"); +>b : Symbol(b, Decl(b.ts, 2, 12)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource7.types b/tsc/testdata/baselines/reference/conformance/importSource7.types new file mode 100644 index 0000000000000..6053530e05503 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource7.types @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource7.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +import source a from "./a.wasm"; +>a : WebAssembly.Module + +export type B = typeof a; +>B : WebAssembly.Module +>a : WebAssembly.Module + +export const b = import.source("./a.wasm"); +>b : Promise +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource8.js b/tsc/testdata/baselines/reference/conformance/importSource8.js new file mode 100644 index 0000000000000..c667a4d0be477 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource8.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importSource/importSource8.ts] //// + +//// [a.d.wasm.ts] +export const a: number; + +//// [b.ts] +import { a } from "./a.wasm"; +import source b from "./a.wasm"; + +const c: number = a; +const d: WebAssembly.Module = b; +const e: Promise = import.source("./a.wasm"); + + +//// [b.js] +import { a } from "./a.wasm"; +import source b from "./a.wasm"; +const c = a; +const d = b; +const e = import.source("./a.wasm"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource8.symbols b/tsc/testdata/baselines/reference/conformance/importSource8.symbols new file mode 100644 index 0000000000000..7b01367f95b6f --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource8.symbols @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/importSource/importSource8.ts] //// + +=== a.d.wasm.ts === +export const a: number; +>a : Symbol(a, Decl(a.d.wasm.ts, 0, 12)) + +=== b.ts === +import { a } from "./a.wasm"; +>a : Symbol(a, Decl(b.ts, 0, 8)) + +import source b from "./a.wasm"; +>b : Symbol(b, Decl(b.ts, 1, 6)) + +const c: number = a; +>c : Symbol(c, Decl(b.ts, 3, 5)) +>a : Symbol(a, Decl(b.ts, 0, 8)) + +const d: WebAssembly.Module = b; +>d : Symbol(d, Decl(b.ts, 4, 5)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>b : Symbol(b, Decl(b.ts, 1, 6)) + +const e: Promise = import.source("./a.wasm"); +>e : Symbol(e, Decl(b.ts, 5, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --)) +>Module : Symbol(WebAssembly.Module, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource8.types b/tsc/testdata/baselines/reference/conformance/importSource8.types new file mode 100644 index 0000000000000..92a77d118292c --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource8.types @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/importSource/importSource8.ts] //// + +=== a.d.wasm.ts === +export const a: number; +>a : number + +=== b.ts === +import { a } from "./a.wasm"; +>a : number + +import source b from "./a.wasm"; +>b : WebAssembly.Module + +const c: number = a; +>c : number +>a : number + +const d: WebAssembly.Module = b; +>d : WebAssembly.Module +>WebAssembly : any +>b : WebAssembly.Module + +const e: Promise = import.source("./a.wasm"); +>e : Promise +>WebAssembly : any +>import.source("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + diff --git a/tsc/testdata/baselines/reference/conformance/importSource9.js b/tsc/testdata/baselines/reference/conformance/importSource9.js new file mode 100644 index 0000000000000..48a877136f26c --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource9.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/importSource/importSource9.ts] //// + +//// [a.d.wasm.ts] +export {}; + +//// [b.ts] +/*comment a*/ import /*comment b*/ source /*comment c*/ a /*comment d*/ from /*comment e*/ "./a.wasm" /*comment f*/ with /*comment g*/ { type: "webassembly" } /*comment h*/; +const b = a; +const c = import /*comment i*/ . /*comment j*/ source /*comment k*/ ("./a.wasm"); + + +//// [b.js] +/*comment a*/ import /*comment b*/ source /*comment c*/ a /*comment d*/ from /*comment e*/ "./a.wasm" /*comment f*/ with /*comment g*/ { type: "webassembly" } /*comment h*/; +const b = a; +const c = import /*comment i*/. /*comment j*/source /*comment k*/("./a.wasm"); diff --git a/tsc/testdata/baselines/reference/conformance/importSource9.symbols b/tsc/testdata/baselines/reference/conformance/importSource9.symbols new file mode 100644 index 0000000000000..b8962a2968ba4 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource9.symbols @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/importSource/importSource9.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +/*comment a*/ import /*comment b*/ source /*comment c*/ a /*comment d*/ from /*comment e*/ "./a.wasm" /*comment f*/ with /*comment g*/ { type: "webassembly" } /*comment h*/; +>a : Symbol(a, Decl(b.ts, 0, 20)) + +const b = a; +>b : Symbol(b, Decl(b.ts, 1, 5)) +>a : Symbol(a, Decl(b.ts, 0, 20)) + +const c = import /*comment i*/ . /*comment j*/ source /*comment k*/ ("./a.wasm"); +>c : Symbol(c, Decl(b.ts, 2, 5)) +>"./a.wasm" : Symbol("./a.wasm", Decl(a.d.wasm.ts, 0, 0)) + diff --git a/tsc/testdata/baselines/reference/conformance/importSource9.types b/tsc/testdata/baselines/reference/conformance/importSource9.types new file mode 100644 index 0000000000000..b3cb9c27ca8b7 --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/importSource9.types @@ -0,0 +1,21 @@ +//// [tests/cases/conformance/importSource/importSource9.ts] //// + +=== a.d.wasm.ts === + +export {}; + +=== b.ts === +/*comment a*/ import /*comment b*/ source /*comment c*/ a /*comment d*/ from /*comment e*/ "./a.wasm" /*comment f*/ with /*comment g*/ { type: "webassembly" } /*comment h*/; +>a : WebAssembly.Module +>type : error + +const b = a; +>b : WebAssembly.Module +>a : WebAssembly.Module + +const c = import /*comment i*/ . /*comment j*/ source /*comment k*/ ("./a.wasm"); +>c : Promise +>import /*comment i*/ . /*comment j*/ source /*comment k*/ ("./a.wasm") : Promise +>source : any +>"./a.wasm" : "./a.wasm" + diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/goToDefinition_sourcePhase.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/goToDefinition_sourcePhase.baseline.jsonc new file mode 100644 index 0000000000000..0aef0b8a1e7e0 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/goToDefinition_sourcePhase.baseline.jsonc @@ -0,0 +1,12 @@ +// === findAllReferences === +// === /b.ts === +// import source [|b|] from "./a.wasm"; +// /*FIND ALL REFS*/[|b|]; +// + + + +// === findAllReferences === +// === /c.ts === +// import source [|c|] from "./a.wasm"; +// /*FIND ALL REFS*/[|c|]; \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinition_sourcePhase.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinition_sourcePhase.baseline.jsonc new file mode 100644 index 0000000000000..3d1a24f6b238f --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/goToDefinition/goToDefinition_sourcePhase.baseline.jsonc @@ -0,0 +1,12 @@ +// === goToDefinition === +// === /b.ts === +// <|import source [|b|] from "./a.wasm";|> +// /*GOTO DEF*/b; +// + + + +// === goToDefinition === +// === /c.ts === +// <|import source [|c|] from "./a.wasm";|> +// /*GOTO DEF*/c; \ No newline at end of file diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource1.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource1.ts new file mode 100644 index 0000000000000..1ae64cbc6a827 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource1.ts @@ -0,0 +1,14 @@ +// @module: esnext, preserve +// @target: esnext +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; + +// @filename: c.ts +import source a from "./a.wasm" with { type: "webassembly" }; +const b: WebAssembly.Module = a; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource10.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource10.ts new file mode 100644 index 0000000000000..c9e6415ba73cb --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource10.ts @@ -0,0 +1,19 @@ +// @module: esnext +// @target: esnext +// @declaration: true +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +import source a from "./a.wasm"; +export { a }; + +// @filename: c.ts +import { a } from "./b.js"; +const b: WebAssembly.Module = a; + +// @filename: d.ts +import * as a from "./b.js"; +const b: WebAssembly.Module = a.a; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource11.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource11.ts new file mode 100644 index 0000000000000..a4a06174560eb --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource11.ts @@ -0,0 +1,12 @@ +// @module: esnext +// @target: esnext + +// @filename: a.ts +export const a = 1; + +// @filename: b.ts +import source a from "./a.js"; +const b = import.source("./a.js"); + +const c: any = a; +const d: Promise = b; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource12.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource12.ts new file mode 100644 index 0000000000000..4ff54c7f9fa0b --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource12.ts @@ -0,0 +1,11 @@ +// @module: preserve +// @target: esnext +// @rewriteRelativeImportExtensions: true + +// @filename: a.ts +export {}; + +// @filename: b.ts +import source a from "./a.ts"; +export { a }; +export const b = import.source("./a.ts"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource13.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource13.ts new file mode 100644 index 0000000000000..00ad1d21a0e11 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource13.ts @@ -0,0 +1,11 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom + +// @filename: a.d.ts +declare module "*.wasm"; + +// @filename: b.ts +import source a from "./a.wasm"; +const b: any = a; +const c: Promise = import.source("./a.wasm"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource14.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource14.ts new file mode 100644 index 0000000000000..fcf2e2a714832 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource14.ts @@ -0,0 +1,12 @@ +// @module: esnext +// @target: esnext + +// @filename: a.d.txt.ts +export {}; + +// @filename: b.ts +import source a from "./a.txt"; +const b = import.source("./a.txt"); + +a; +b; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource15.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource15.ts new file mode 100644 index 0000000000000..0b90c67612d87 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource15.ts @@ -0,0 +1,58 @@ +// @module: esnext +// @target: esnext +// @allowJs: true +// @noEmit: true + +// @filename: a.js +export default 1; +export const a = 2; + +// @filename: b.js +import source * as a from "./a.js"; + +// @filename: c.js +import source { a } from "./a.js"; + +// @filename: d.js +import source a, { a as b } from "./a.js"; + +// @filename: e.js +import source "./a.js"; + +// @filename: f.js +import.source; +(import.source)("./a.js"); +Function(import.source); +import.source.unknown; + +import.source(); +import.source("./a.js", {}, {}); +import.source?.("./a.js"); +import.source("./a.js"); +import.source(...["./a.js"]); + +// @filename: g.js +new import.source("./a.js"); + +// @filename: h.js +typeof import.source; + +// @filename: i.js +import.a("./a.js"); + +// @filename: j.js +import source a from "./a.js" with { type: "javascript" }; +const b = import.source("./a.js", { with: { type: "javascript" } }); +a; +b; + +// @filename: k.js +const a = import.source("./a.js", { with: { type: "javascript" } }); +a; + +// @filename: l.js +import s\u006furce from "./a.js"; +source; + +// @filename: m.js +import.s\u006furce("./a.js"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource16.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource16.ts new file mode 100644 index 0000000000000..1c7bf6b450dba --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource16.ts @@ -0,0 +1,22 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom +// @strict: true +// @declaration: true +// @noImplicitReferences: true + +// @filename: a.wasm + +// @filename: b.ts +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +export type B = typeof a; +export { a }; + +export const c = import.source("./a.wasm"); +const d: Promise = c; + +// @filename: c.ts +import { a, c } from "./b.js"; +const e: WebAssembly.Module = a; +const f: Promise = c; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource17.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource17.ts new file mode 100644 index 0000000000000..fa049b1cb26ba --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource17.ts @@ -0,0 +1,20 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @strict: true +// @noImplicitReferences: true + +// @filename: a.wasm + +// @filename: b.js +import source a from "./a.wasm"; +const b = import.source("./a.wasm"); + +/** @type {WebAssembly.Module} */ +const c = a; + +/** @type {Promise} */ +const d = b; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource18.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource18.ts new file mode 100644 index 0000000000000..b9567ea209e5e --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource18.ts @@ -0,0 +1,14 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom +// @strict: true +// @noImplicitReferences: true + +// @filename: a.wasm + +// @filename: b.ts +import source a from "./a.wasm"; +import { b } from "./a.wasm"; + +const c: WebAssembly.Module = a; +b; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource19.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource19.ts new file mode 100644 index 0000000000000..7e87bdc8886ef --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource19.ts @@ -0,0 +1,11 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom +// @strict: true + +// @filename: a.ts +import source a from "./missing.wasm"; +const b = import.source("./missing.wasm"); + +a; +b; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource2.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource2.ts new file mode 100644 index 0000000000000..10fdf52bfa9d6 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource2.ts @@ -0,0 +1,28 @@ +// @module: esnext, preserve +// @target: esnext +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +export {}; +const a = import.source("./a.wasm"); +const b: Promise = a; + +// @filename: c.ts +export {}; +const a = import.source("./a.wasm", { with: { type: "webassembly" } }); +const b: Promise = a; + +// @filename: d.ts +export {}; +const a = import.source("./a.wasm",); +const b: Promise = a; +const c = import.source("./a.wasm", { with: { type: "webassembly" } },); +const d: Promise = c; + +// @filename: e.ts +export {}; +const a = import.source(`./a.wasm`); +const b: Promise = a; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource20.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource20.ts new file mode 100644 index 0000000000000..ac5d87741dfdd --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource20.ts @@ -0,0 +1,24 @@ +// @module: esnext +// @moduleResolution: bundler +// @target: esnext +// @lib: esnext,dom +// @strict: true +// @noImplicitReferences: true + +// @filename: node_modules/a/package.json +{"name":"a","exports":{"types":"./index.d.ts","default":"./a.wasm"}} + +// @filename: node_modules/a/index.d.ts +declare const a: string; +export default a; + +// @filename: node_modules/a/a.wasm + +// @filename: b.ts +import a from "a"; +import source b from "a"; +const c: string = a; +const d: WebAssembly.Module = b; + +const e = import.source("a"); +const f: Promise = e; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource21.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource21.ts new file mode 100644 index 0000000000000..a3d28f84eca2a --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource21.ts @@ -0,0 +1,39 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom +// @noImplicitReferences: true + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +import source a from "./a.wasm"; +export { a }; + +// @filename: c.ts +import source a from "././a.wasm"; +export { a }; + +// @filename: d.ts +export * from "./b.js"; +export * from "./c.js"; + +// @filename: e.wasm + +// @filename: f.ts +import source e from "./e.wasm"; +export { e }; + +// @filename: g.ts +import source e from "././e.wasm"; +export { e }; + +// @filename: h.ts +export * from "./f.js"; +export * from "./g.js"; + +// @filename: i.ts +import { a } from "./d.js"; +import { e } from "./h.js"; +const b: WebAssembly.Module = a; +const c: WebAssembly.Module = e; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource22.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource22.ts new file mode 100644 index 0000000000000..fb485f98afe1d --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource22.ts @@ -0,0 +1,16 @@ +// @module: nodenext +// @target: esnext +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.mts +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +const c: Promise = import.source("./a.wasm"); + +// @filename: c.cts +import source a from "./a.wasm"; +const b: WebAssembly.Module = a; +const c: Promise = import.source("./a.wasm"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource23.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource23.ts new file mode 100644 index 0000000000000..f69f199810734 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource23.ts @@ -0,0 +1,10 @@ +// @module: esnext +// @target: esnext + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +import source a from "./a.d.wasm.ts"; +a; +import.source("./a.d.wasm.ts"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource24.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource24.ts new file mode 100644 index 0000000000000..99924811258be --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource24.ts @@ -0,0 +1,12 @@ +// @module: nodenext +// @target: esnext +// @rewriteRelativeImportExtensions: true + +// @filename: package.json +{"type":"commonjs"} + +// @filename: a.ts +export {}; + +// @filename: b.cts +export const a = import.source("./a.ts"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource25.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource25.ts new file mode 100644 index 0000000000000..234e4271731a0 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource25.ts @@ -0,0 +1,33 @@ +// @module: esnext +// @target: esnext + +// @filename: a.d.ts +declare module "*.txt"; + +// @filename: b.ts +import source a from "./a.txt"; +export { a as value }; + +// @filename: c.ts +import source a from "././a.txt"; +export { a as value }; + +// @filename: d.ts +export * from "./b.js"; +export * from "./c.js"; + +// @filename: e.ts +import { value } from "./d.js"; +value; + +// @filename: f.ts +import source a from "./b.txt"; +export { a as value }; + +// @filename: g.ts +export * from "./b.js"; +export * from "./f.js"; + +// @filename: h.ts +import { value } from "./g.js"; +value; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource26.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource26.ts new file mode 100644 index 0000000000000..35fd883c0c777 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource26.ts @@ -0,0 +1,14 @@ +// @module: commonjs, nodenext +// @target: esnext +// @allowJs: true +// @noEmit: true + +// @filename: package.json +{"type":"commonjs"} + +// @filename: a.js +export default 1; + +// @filename: b.js +import source a from "./a.js"; +const b = import.source("./a.js"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource27.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource27.ts new file mode 100644 index 0000000000000..c0c1cf9a94845 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource27.ts @@ -0,0 +1,31 @@ +// @module: esnext +// @target: esnext +// @strict: true +// @noEmit: true +// @noImplicitReferences: true +// @jsx: preserve + +// @filename: a.js +export const a = 1; + +// @filename: b.mjs +export const b = 1; + +// @filename: c.cjs +exports.c = 1; + +// @filename: d.jsx +export const d =
; + +// @filename: e.ts +import source a from "./a.js"; +import source b from "./b.mjs"; +import source c from "./c.cjs"; +import source d from "./d.jsx"; +const e = import.source("./a.js"); + +const f: any = a; +const g: any = b; +const h: any = c; +const i: any = d; +const j: Promise = e; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts new file mode 100644 index 0000000000000..0ea38ba61c67b --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts @@ -0,0 +1,45 @@ +// @module: preserve +// @target: esnext +// @lib: esnext,dom + +// @filename: a.ts +export default 1; +export const a = 2; + +// @filename: b.ts +import source from "./a.js"; +const a: number = source; + +// @filename: c.ts +import source, { a } from "./a.js"; +const b: number = source + a; + +// @filename: d.ts +import source = require("./a"); +const a: typeof source = source; + +// @filename: e.ts +const source = 1; +const a: number = source; + +// @filename: f.d.wasm.ts +export {}; + +// @filename: g.ts +import source from from "./f.wasm"; +const a: WebAssembly.Module = from; + +// @filename: h.ts +import source type from "./f.wasm"; +const a: WebAssembly.Module = type; + +// @filename: i.ts +import source source from "./f.wasm"; +const a: WebAssembly.Module = source; + +// @filename: j.ts +import +source +a +from "./f.wasm"; +const b: WebAssembly.Module = a; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource4.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource4.ts new file mode 100644 index 0000000000000..48b49899a91c4 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource4.ts @@ -0,0 +1,21 @@ +// @module: esnext +// @target: esnext + +// @filename: a.ts +export default 1; +export const a = 2; + +// @filename: b.ts +import source * as a from "./a.js"; + +// @filename: c.ts +import source { a } from "./a.js"; + +// @filename: d.ts +import source a, { a as b } from "./a.js"; + +// @filename: e.ts +import source "./a.js"; + +// @filename: f.ts +import source type a from "./a.js"; diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource5.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource5.ts new file mode 100644 index 0000000000000..86cb9d583cde5 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource5.ts @@ -0,0 +1,29 @@ +// @module: esnext +// @target: esnext + +// @filename: a.ts +export default 1; + +// @filename: b.ts +import.source; +(import.source)("./a.js"); +Function(import.source); +import.source.unknown; + +import.source(); +import.source("./a.js", {}, {}); +import.source?.("./a.js"); +import.source("./a.js"); +import.source(...["./a.js"]); + +// @filename: c.ts +new import.source("./a.js"); + +// @filename: d.ts +new import.source("./a.js").a; + +// @filename: e.ts +typeof import.source; + +// @filename: f.ts +import.a("./a.js"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource6.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource6.ts new file mode 100644 index 0000000000000..0d7d11a9d6c56 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource6.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @target: esnext + +// @filename: a.ts +export default 1; + +// @filename: b.ts +import source a from "./a.js"; +const b = import.source("./a.js"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource7.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource7.ts new file mode 100644 index 0000000000000..6f3f6ee53d39b --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource7.ts @@ -0,0 +1,12 @@ +// @module: esnext +// @target: esnext +// @declaration: true +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +import source a from "./a.wasm"; +export type B = typeof a; +export const b = import.source("./a.wasm"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource8.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource8.ts new file mode 100644 index 0000000000000..b03360e68b321 --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource8.ts @@ -0,0 +1,15 @@ +// @module: esnext +// @target: esnext +// @allowArbitraryExtensions: true +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export const a: number; + +// @filename: b.ts +import { a } from "./a.wasm"; +import source b from "./a.wasm"; + +const c: number = a; +const d: WebAssembly.Module = b; +const e: Promise = import.source("./a.wasm"); diff --git a/tsc/testdata/tests/cases/conformance/importSource/importSource9.ts b/tsc/testdata/tests/cases/conformance/importSource/importSource9.ts new file mode 100644 index 0000000000000..d10fa76be217f --- /dev/null +++ b/tsc/testdata/tests/cases/conformance/importSource/importSource9.ts @@ -0,0 +1,11 @@ +// @module: esnext +// @target: esnext +// @lib: esnext,dom + +// @filename: a.d.wasm.ts +export {}; + +// @filename: b.ts +/*comment a*/ import /*comment b*/ source /*comment c*/ a /*comment d*/ from /*comment e*/ "./a.wasm" /*comment f*/ with /*comment g*/ { type: "webassembly" } /*comment h*/; +const b = a; +const c = import /*comment i*/ . /*comment j*/ source /*comment k*/ ("./a.wasm");