diff --git a/web-infras/common/src/ast.ts b/web-infras/common/src/ast.ts index ad9d1ec8..9a2f64fc 100644 --- a/web-infras/common/src/ast.ts +++ b/web-infras/common/src/ast.ts @@ -356,6 +356,29 @@ export interface TSInstantiationExpression extends ExpressionModuleItem { expression: Expression; } +export interface TSTypeAssertionExpression extends ExpressionModuleItem { + kind: SyntaxKinds.TSTypeAssertionExpression; + expression: Expression; + typeAnnotation: TSTypeNode; +} + +export interface TSAsExpression extends ExpressionModuleItem { + kind: SyntaxKinds.TSAsExpression; + expression: Expression; + typeAnnotation: TSTypeNode; +} + +export interface TSSatisfiesExpression extends ExpressionModuleItem { + kind: SyntaxKinds.TSSatisfiesExpression; + expression: Expression; + typeAnnotation: TSTypeNode; +} + +export interface TSNonNullExpression extends ExpressionModuleItem { + kind: SyntaxKinds.TSNonNullExpression; + expression: Expression; +} + export type Expression = // jsx element | JSXElement @@ -398,7 +421,11 @@ export type Expression = | AssigmentExpression | SequenceExpression // TS expression - | TSInstantiationExpression; + | TSInstantiationExpression + | TSTypeAssertionExpression + | TSAsExpression + | TSSatisfiesExpression + | TSNonNullExpression; export interface ExpressionStatement extends ModuleItem { kind: SyntaxKinds.ExpressionStatement; expr: Expression; @@ -447,7 +474,11 @@ export type Pattern = | ObjectPattern | ArrayPattern | Identifier - | MemberExpression; + | MemberExpression + | TSAsExpression + | TSTypeAssertionExpression + | TSSatisfiesExpression + | TSNonNullExpression; /** ========================== * Statement @@ -540,6 +571,8 @@ export interface ForOfStatement extends ModuleItem { await: boolean; body: Statement; } +// TODO. better Type +// type ForOfInStatementLeft = VariableDeclaration | Pattern | TSAsExpression | TSTypeAssertionExpression; export interface ForInStatement extends ModuleItem { kind: SyntaxKinds.ForInStatement; left: Expression | VariableDeclaration; @@ -648,12 +681,9 @@ export interface Decorator extends ModuleItem { kind: SyntaxKinds.Decorator; expression: Expression; } -export type Declaration = - | FunctionDeclaration - | VariableDeclaration - | ClassDeclaration - | TSTypeAliasDeclaration - | TSInterfaceDeclaration; +export type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration | TSDeclaration; + +type TSDeclaration = TSTypeAliasDeclaration | TSInterfaceDeclaration | TSEnumDeclaration | TSDeclareFunction; /** ========================================== * Import Declaration @@ -696,7 +726,13 @@ export interface ExportSpecifier extends ModuleItem { } export interface ExportDefaultDeclaration extends ModuleItem { kind: SyntaxKinds.ExportDefaultDeclaration; - declaration: FunctionDeclaration | FunctionExpression | ClassDeclaration | ClassExpression | Expression; + declaration: + | FunctionDeclaration + | FunctionExpression + | ClassDeclaration + | ClassExpression + | Expression + | TSDeclaration; } export interface ExportAllDeclaration extends ModuleItem { kind: SyntaxKinds.ExportAllDeclaration; @@ -803,9 +839,29 @@ export interface TSTypeParameterInstantiation extends ModuleItem { export interface TSFunctionType extends TSFunctionSignatureBase { kind: SyntaxKinds.TSFunctionType; } +export interface TSDeclareFunction extends Omit, ModuleItem { + kind: SyntaxKinds.TSDeclareFunction; +} export interface TSConstrcutorType extends TSFunctionSignatureBase { kind: SyntaxKinds.TSConstructorType; } +export interface TSEnumDeclaration extends ModuleItem { + id: Identifier; + kind: SyntaxKinds.TSEnumDeclaration; + body: TSEnumBody; +} + +export interface TSEnumBody extends ModuleItem { + kind: SyntaxKinds.TSEnumBody; + members: Array; +} +export interface TSEnumMember extends ModuleItem { + kind: SyntaxKinds.TSEnumMember; + computed: boolean; + id: Identifier; + init: Expression | undefined; +} + export interface TSTypeAliasDeclaration extends ModuleItem { kind: SyntaxKinds.TSTypeAliasDeclaration; name: Identifier; @@ -817,6 +873,11 @@ export interface TSInterfaceDeclaration extends ModuleItem { name: Identifier; body: TSInterfaceBody; typeParameters: TSTypeParameterDeclaration | undefined; + extends: Array; +} +export interface TSInterfaceHeritage extends ModuleItem { + typeName: TSEntityName; + typeArguments: TSTypeParameterInstantiation | undefined; } export interface TSInterfaceBody extends ModuleItem { kind: SyntaxKinds.TSInterfaceBody; diff --git a/web-infras/common/src/factory.ts b/web-infras/common/src/factory.ts index 6061576c..6d71118f 100644 --- a/web-infras/common/src/factory.ts +++ b/web-infras/common/src/factory.ts @@ -1769,6 +1769,7 @@ export function createTSInterfaceBody( export function createTSInterface( name: AST.TSInterfaceDeclaration["name"], typeParameters: AST.TSInterfaceDeclaration["typeParameters"], + extendsTypes: AST.TSInterfaceDeclaration["extends"], body: AST.TSInterfaceDeclaration["body"], start: SourcePosition, end: SourcePosition, @@ -1777,12 +1778,28 @@ export function createTSInterface( kind: SyntaxKinds.TSInterfaceDeclaration, name, typeParameters, + extends: extendsTypes, body, start, end, }; } +export function createTSInterfaceHeritage( + typeName: AST.TSEntityName, + typeArguments: AST.TSTypeReference["typeArguments"], + start: SourcePosition, + end: SourcePosition, +): AST.TSInterfaceHeritage { + return { + kind: SyntaxKinds.TSInterfaceHeritage, + typeName, + typeArguments, + start, + end, + }; +} + export function createTSTypeParameterInstantiation( params: Array, start: SourcePosition, @@ -2009,3 +2026,129 @@ export function createTSInstantiationExpression( end, }; } + +export function createTSTypeAssertionExpression( + expression: AST.TSTypeAssertionExpression["expression"], + typeAnnotation: AST.TSTypeAssertionExpression["typeAnnotation"], + start: SourcePosition, + end: SourcePosition, +): AST.TSTypeAssertionExpression { + return { + kind: SyntaxKinds.TSTypeAssertionExpression, + expression, + typeAnnotation, + start, + end, + }; +} + +export function createTSAsExpression( + expression: AST.TSAsExpression["expression"], + typeAnnotation: AST.TSAsExpression["typeAnnotation"], + start: SourcePosition, + end: SourcePosition, +): AST.TSAsExpression { + return { + kind: SyntaxKinds.TSAsExpression, + expression, + typeAnnotation, + start, + end, + }; +} + +export function createTSSatisfiesExpression( + expression: AST.TSSatisfiesExpression["expression"], + typeAnnotation: AST.TSSatisfiesExpression["typeAnnotation"], + start: SourcePosition, + end: SourcePosition, +): AST.TSSatisfiesExpression { + return { + kind: SyntaxKinds.TSSatisfiesExpression, + expression, + typeAnnotation, + start, + end, + }; +} + +export function createTSNonNullExpression( + expression: AST.TSNonNullExpression["expression"], + start: SourcePosition, + end: SourcePosition, +): AST.TSNonNullExpression { + return { + kind: SyntaxKinds.TSNonNullExpression, + expression, + start, + end, + }; +} + +export function createTSEnumDeclaration( + id: AST.TSEnumDeclaration["id"], + body: AST.TSEnumDeclaration["body"], + start: SourcePosition, + end: SourcePosition, +): AST.TSEnumDeclaration { + return { + kind: SyntaxKinds.TSEnumDeclaration, + id, + body, + start, + end, + }; +} + +export function createTSEnumBody( + members: AST.TSEnumBody["members"], + start: SourcePosition, + end: SourcePosition, +): AST.TSEnumBody { + return { + kind: SyntaxKinds.TSEnumBody, + members, + start, + end, + }; +} + +export function createTSEnumMember( + id: AST.TSEnumMember["id"], + computed: AST.TSEnumMember["computed"], + init: AST.TSEnumMember["init"], + start: SourcePosition, + end: SourcePosition, +): AST.TSEnumMember { + return { + kind: SyntaxKinds.TSEnumMember, + computed, + id, + init, + start, + end, + }; +} + +export function createTSDeclarFunction( + name: AST.TSDeclareFunction["name"], + returnType: AST.TSDeclareFunction["returnType"], + params: AST.TSDeclareFunction["params"], + typeParameters: AST.TSDeclareFunction["typeParameters"], + generator: AST.TSDeclareFunction["generator"], + async: AST.TSDeclareFunction["async"], + start: SourcePosition, + end: SourcePosition, +): AST.TSDeclareFunction { + return { + kind: SyntaxKinds.TSDeclareFunction, + name, + params, + returnType, + typeParameters, + generator, + async, + start, + end, + }; +} diff --git a/web-infras/common/src/kind.ts b/web-infras/common/src/kind.ts index 7f0d6e2f..034bb5ce 100644 --- a/web-infras/common/src/kind.ts +++ b/web-infras/common/src/kind.ts @@ -262,6 +262,7 @@ export enum SyntaxKinds { // ========= Type Interface and Type Alias ===== TSTypeAliasDeclaration, TSInterfaceDeclaration, + TSInterfaceHeritage, TSInterfaceBody, TSTypeLiteral, TSCallSignatureDeclaration, @@ -269,8 +270,16 @@ export enum SyntaxKinds { TSIndexSignature, TSPropertySignature, TSMethodSignature, + // ======== Type Enum + TSEnumDeclaration, + TSEnumBody, + TSEnumMember, // ========= Type Expression TSInstantiationExpression, + TSTypeAssertionExpression, + TSAsExpression, + TSSatisfiesExpression, + TSNonNullExpression, // ========= Type Parameter TSTypeParameterInstantiation, TSTypeParameterDeclaration, @@ -284,6 +293,7 @@ export enum SyntaxKinds { TSTypeQuery, TSTupleType, TSLiteralType, + TSDeclareFunction, // ======= Atom Basic Type ====== TSStringKeyword, TSNumberKeyword, @@ -774,6 +784,15 @@ export const SytaxKindsMapLexicalLiteral: Record = { [SyntaxKinds.TSLiteralType]: "TSLiteralType", [SyntaxKinds.TSVoidKeyword]: "TSVoidKeyword", [SyntaxKinds.TSInstantiationExpression]: "TSInstantiationExpression", + [SyntaxKinds.TSInterfaceHeritage]: "TSInterfaceHeritage", + [SyntaxKinds.TSTypeAssertionExpression]: "TSTypeAssertionExpression", + [SyntaxKinds.TSAsExpression]: "TSAsExpression", + [SyntaxKinds.TSSatisfiesExpression]: "TSSatisfiesExpression", + [SyntaxKinds.TSNonNullExpression]: "TSNonNullExpression", + [SyntaxKinds.TSEnumDeclaration]: "TSEnumDeclaration", + [SyntaxKinds.TSEnumBody]: "TSEnumBody", + [SyntaxKinds.TSEnumMember]: "TSEnumMember", + [SyntaxKinds.TSDeclareFunction]: "TSDeclareFunction", }; /** =================================== * Union SytaxKinds diff --git a/web-infras/common/src/visitor.ts b/web-infras/common/src/visitor.ts index 990d3c86..aac40f6b 100644 --- a/web-infras/common/src/visitor.ts +++ b/web-infras/common/src/visitor.ts @@ -139,6 +139,15 @@ import { TSUnionType, TSInstantiationExpression, TSVoidKeyword, + TSInterfaceHeritage, + TSTypeAssertionExpression, + TSAsExpression, + TSSatisfiesExpression, + TSNonNullExpression, + TSEnumDeclaration, + TSEnumBody, + TSEnumMember, + TSDeclareFunction, } from "./ast"; import { SyntaxKinds } from "./kind"; @@ -291,6 +300,15 @@ export type Visitor = { [SyntaxKinds.TSUnknowKeyword]?: (node: TSUnknowKeyword, visitor: Visitor) => void; [SyntaxKinds.TSVoidKeyword]?: (node: TSVoidKeyword, visitor: Visitor) => void; [SyntaxKinds.TSInstantiationExpression]?: (node: TSInstantiationExpression, visitor: Visitor) => void; + [SyntaxKinds.TSInterfaceHeritage]?: (node: TSInterfaceHeritage, visitor: Visitor) => void; + [SyntaxKinds.TSTypeAssertionExpression]?: (node: TSTypeAssertionExpression, visitor: Visitor) => void; + [SyntaxKinds.TSAsExpression]?: (node: TSAsExpression, visitor: Visitor) => void; + [SyntaxKinds.TSSatisfiesExpression]?: (node: TSSatisfiesExpression, visitor: Visitor) => void; + [SyntaxKinds.TSNonNullExpression]?: (node: TSNonNullExpression, visitor: Visitor) => void; + [SyntaxKinds.TSEnumDeclaration]?: (node: TSEnumDeclaration, visitor: Visitor) => void; + [SyntaxKinds.TSEnumBody]?: (node: TSEnumBody, visitor: Visitor) => void; + [SyntaxKinds.TSEnumMember]?: (node: TSEnumMember, visitor: Visitor) => void; + [SyntaxKinds.TSDeclareFunction]?: (node: TSDeclareFunction, visitor: Visitor) => void; }; export const PropagationtVisitorTable: Visitor = { @@ -754,6 +772,7 @@ export const PropagationtVisitorTable: Visitor = { [SyntaxKinds.TSInterfaceDeclaration]: function (node: TSInterfaceDeclaration, visitor: Visitor) { visitNode(node.body, visitor); visitNode(node.typeParameters, visitor); + visitNodes(node.extends, visitor); }, [SyntaxKinds.TSTypeLiteral]: function (node: TSTypeLiteral, visitor: Visitor) { visitNodes(node.members, visitor); @@ -826,6 +845,42 @@ export const PropagationtVisitorTable: Visitor = { visitNode(node.constraint, visitor); visitNode(node.default, visitor); }, + [SyntaxKinds.TSInterfaceHeritage]: function (node: TSInterfaceHeritage, visitor: Visitor) { + visitNode(node.typeName, visitor); + visitNode(node.typeArguments, visitor); + }, + [SyntaxKinds.TSTypeAssertionExpression]: function (node: TSTypeAssertionExpression, visitor: Visitor) { + visitNode(node.expression, visitor); + visitNode(node.typeAnnotation, visitor); + }, + [SyntaxKinds.TSAsExpression]: function (node: TSAsExpression, visitor: Visitor) { + visitNode(node.expression, visitor); + visitNode(node.typeAnnotation, visitor); + }, + [SyntaxKinds.TSSatisfiesExpression]: function (node: TSSatisfiesExpression, visitor: Visitor) { + visitNode(node.expression, visitor); + visitNode(node.typeAnnotation, visitor); + }, + [SyntaxKinds.TSNonNullExpression]: function (node: TSNonNullExpression, visitor: Visitor) { + visitNode(node.expression, visitor); + }, + [SyntaxKinds.TSEnumDeclaration]: function (node: TSEnumDeclaration, visitor: Visitor) { + visitNode(node.id, visitor); + visitNode(node.body, visitor); + }, + [SyntaxKinds.TSEnumBody]: function (node: TSEnumBody, visitor: Visitor) { + visitNodes(node.members, visitor); + }, + [SyntaxKinds.TSEnumMember]: function (node: TSEnumMember, visitor: Visitor) { + visitNode(node.init, visitor); + visitNode(node.id, visitor); + }, + [SyntaxKinds.TSDeclareFunction]: function (node: TSDeclareFunction, visitor: Visitor) { + visitNode(node.name, visitor); + visitNodes(node.params, visitor); + visitNode(node.typeParameters, visitor); + visitNode(node.returnType, visitor); + }, }; export function visitNode(node: T | null | undefined, visitor: Visitor) { diff --git a/web-infras/parser/src/lexer/lexer.ts b/web-infras/parser/src/lexer/lexer.ts index 994c7238..8eadd496 100644 --- a/web-infras/parser/src/lexer/lexer.ts +++ b/web-infras/parser/src/lexer/lexer.ts @@ -347,16 +347,17 @@ export function createLexer(code: string) { * * @returns */ - function reLexGtRelateToken() { + function reLexGtRelateToken(allowAssign: boolean) { switch (state.token.kind) { // `>=` to `>`, `=` - // case SyntaxKinds.GeqtOperator: { - // state.cursor.pos -= 2; - // startToken(); - // eatChar(); - // finishToken(SyntaxKinds.GtOperator); - // return; - // } + case SyntaxKinds.GeqtOperator: { + if (!allowAssign) return; + state.cursor.pos -= 2; + startToken(); + eatChar(); + finishToken(SyntaxKinds.GtOperator); + return; + } // `>>` to `>`, `>` case SyntaxKinds.BitwiseRightShiftOperator: { state.cursor.pos -= 2; diff --git a/web-infras/parser/src/parser/parser.ts b/web-infras/parser/src/parser/parser.ts index 495876ef..09720b19 100644 --- a/web-infras/parser/src/parser/parser.ts +++ b/web-infras/parser/src/parser/parser.ts @@ -58,7 +58,6 @@ import { ObjectPatternProperty, SyntaxKinds, UnaryOperators, - BinaryOperators, AssigmentOperators, AssigmentOperatorKinds, BinaryOperatorKinds, @@ -148,6 +147,11 @@ import { TSTupleType, TSLiteralType, TSVoidKeyword, + TSInterfaceHeritage, + TSEnumDeclaration, + TSEnumBody, + TSEnumMember, + TSDeclareFunction, } from "web-infra-common"; import { ExpectToken } from "./type"; import { ErrorMessageMap } from "./error"; @@ -865,8 +869,9 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt (duplicateType === SymbolType.Var && lexicalScopeRecorder.isInCatch()) || duplicateType === SymbolType.Let || duplicateType === SymbolType.Const - ) + ) { raiseError(ErrorMessageMap.v8_error_duplicate_identifier, position); + } } const isExportAlreadyExist = declarateExportSymbolIfInContext(name, position); if (isExportAlreadyExist) { @@ -989,6 +994,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt case SyntaxKinds.FunctionKeyword: case SyntaxKinds.ClassKeyword: case SyntaxKinds.AtPunctuator: + case SyntaxKinds.EnumKeyword: return parseDeclaration(); case SyntaxKinds.Identifier: { const declar = tryParseDeclarationWithIdentifierStart(); @@ -1043,16 +1049,17 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt const token = getToken(); switch (token) { // async function declaration - case SyntaxKinds.Identifier: { + case SyntaxKinds.Identifier: + case SyntaxKinds.EnumKeyword: { const declar = tryParseDeclarationWithIdentifierStart(); if (!declar) { - throw createUnreachError(); + throw createUnexpectError(); } return declar; } // function delcaration case SyntaxKinds.FunctionKeyword: - return parseFunctionDeclaration(false); + return parseFunctionDeclaration(false, false); case SyntaxKinds.ConstKeyword: case SyntaxKinds.LetKeyword: return parseVariableDeclaration(); @@ -1065,6 +1072,12 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } } function tryParseDeclarationWithIdentifierStart(): Declaration | undefined { + if (getEscFlag()) { + return; + } + if (match(SyntaxKinds.EnumKeyword)) { + return parseTSEnumDeclaration(); + } const { kind: lookaheadToken, lineTerminatorFlag } = lookahead(); const sourceValue = getSourceValue(); switch (sourceValue) { @@ -1076,7 +1089,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt if (getLineTerminatorFlag()) { raiseError(ErrorMessageMap.missing_semicolon, getStartPosition()); } - return parseFunctionDeclaration(true); + return parseFunctionDeclaration(true, false); } case "type": { if (!(lookaheadToken === SyntaxKinds.Identifier && !lineTerminatorFlag)) { @@ -1170,11 +1183,22 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt * for MemberExpression and Identifier */ if (node.parentheses) { - if (isBinding || (!isBinding && !isMemberExpression(node) && !isIdentifer(node))) + if (!isParanValidationInPattern(isBinding, node)) // recoverable error raiseError(ErrorMessageMap.babel_error_invalid_parenthesized_pattern, node.start); } switch (node.kind) { + case SyntaxKinds.TSAsExpression: + case SyntaxKinds.TSTypeAssertionExpression: + case SyntaxKinds.TSSatisfiesExpression: + case SyntaxKinds.TSNonNullExpression: + if (!isBinding) { + // only accept id, member expression and nested TS expression. + node.expression = exprToPattern(node.expression, isBinding) as Expression; + return node; + } else { + throw createMessageError(ErrorMessageMap.syntax_error_invalid_assignment_left_hand_side); + } case SyntaxKinds.AssigmentExpression: { return assignmentExpressionToAssignmentPattern(node, isBinding); } @@ -1200,6 +1224,30 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt throw createMessageError(ErrorMessageMap.syntax_error_invalid_assignment_left_hand_side); } } + function isParanValidationInPattern(isBinding: boolean, expr: Expression): boolean { + if (isBinding) return false; + return isAssignable(expr); + } + /** + * Is a node match the DestructuringAssignmentTarget in ECMA spec. + * @param node + * @returns + */ + function isAssignable(node: ModuleItem) { + switch (node.kind) { + case SyntaxKinds.Identifier: + case SyntaxKinds.MemberExpression: + return true; + case SyntaxKinds.TSAsExpression: + case SyntaxKinds.TSTypeAssertionExpression: + case SyntaxKinds.TSSatisfiesExpression: + case SyntaxKinds.TSNonNullExpression: + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return isAssignable((node as any).expression); + default: + return false; + } + } /** * ## Transform Assignment Expression * @param expr @@ -1232,11 +1280,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt if (property.value && isMemberExpression(property.value)) { raiseError(ErrorMessageMap.babel_error_binding_member_expression, property.start); } - if ( - property.value && - (isMemberExpression(property.value) || isIdentifer(property.value)) && - property.value.parentheses - ) { + if (property.value && isAssignable(property.value) && (property.value as Expression).parentheses) { // recoverable error raiseError(ErrorMessageMap.babel_error_invalid_parenthesized_pattern, leftValue.start); } @@ -1259,8 +1303,9 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } } } - if (isMemberExpression(leftValue) || isIdentifer(leftValue)) { - if (leftValue.parentheses) { + if (isAssignable(leftValue)) { + const expr = leftValue as Expression; + if (expr.parentheses) { // recoverable error raiseError(ErrorMessageMap.babel_error_invalid_parenthesized_pattern, leftValue.start); } @@ -1317,7 +1362,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt * - `AssignmentRestElement` in `ArrayAssignmentPattern` * * According to production rule, `BindingRestElement`'s argument can only be identifier or ObjectPattern - * or ArrayPattern, and argument of `AssignmentRestProperty` can only be identifier or memberExpression. + * or ArrayPattern, and argument of `AssignmentRestElement` can only be identifier or memberExpression. * ``` * BindingRestElement := ... BindingIdentifier * := ... BindingPattern @@ -1394,7 +1439,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt ); } } else { - if (!isIdentifer(argument) && !isMemberExpression(argument)) { + if (!isAssignable(argument)) { // recoverable error raiseError( ErrorMessageMap.v8_error_rest_assignment_property_must_be_followed_by_an_identifier_in_declaration_contexts, @@ -1924,12 +1969,16 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt raiseError(ErrorMessageMap.v8_error_label_has_already_been_declared, label.start); } expect(SyntaxKinds.ColonPunctuator); - const labeled = match(SyntaxKinds.FunctionKeyword) ? parseFunctionDeclaration(false) : parseStatement(); + const labeled = match(SyntaxKinds.FunctionKeyword) + ? parseFunctionDeclaration(false, false) + : parseStatement(); lexicalScopeRecorder.exitVirtualBlockScope(); - staticSematicEarlyErrorForLabelStatement(labeled); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + staticSematicEarlyErrorForLabelStatement(labeled as any); return Factory.createLabeledStatement( label, - labeled, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + labeled as any, cloneSourcePosition(label.start), cloneSourcePosition(labeled.end), ); @@ -2156,14 +2205,64 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt declarations[declarations.length - 1].end, ); } - function parseFunctionDeclaration(isAsync: boolean) { + function parseFunctionDeclaration( + isAsync: boolean, + isDefault: boolean, + ): FunctionDeclaration | TSDeclareFunction { enterFunctionScope(isAsync); - const func = parseFunction(false); - exitFunctionScope(false); - // for function declaration, symbol should declar in parent scope. - const name = func.name!; - delcarateFcuntionSymbol(name.name, func.generator, func.start); - return Factory.transFormFunctionToFunctionDeclaration(func); + const { start } = expect(SyntaxKinds.FunctionKeyword); + let generator = false; + if (match(SyntaxKinds.MultiplyOperator)) { + generator = true; + setCurrentFunctionContextAsGenerator(); + nextToken(); + } + const [[name, typeParameters, params], scope] = parseWithCatpureLayer(() => { + const name = parseFunctionName(isDefault); + if (!name && !isDefault) { + // recoverable error + raiseError(ErrorMessageMap.syntax_error_function_statement_requires_a_name, getStartPosition()); + } + const typeParameters = tryParseTSTypeParameterDeclaration(false); + const params = parseFunctionParam(); + return [name, typeParameters, params]; + }); + const returnType = tryParseTSReturnTypeOrTypePredicate(SyntaxKinds.ColonPunctuator); + if (match(SyntaxKinds.BracesLeftPunctuator)) { + const body = parseFunctionBody(); + postStaticSematicEarlyErrorForStrictModeOfFunction(name, scope); + const func = Factory.createFunction( + name, + body, + params, + typeParameters, + returnType, + generator, + isCurrentScopeParseAwaitAsExpression(), + start, + cloneSourcePosition(body.end), + ); + exitFunctionScope(false); + // for function declaration, symbol should declar in parent scope. + if (name) { + delcarateFcuntionSymbol(name.name, func.generator, func.start); + } + return Factory.transFormFunctionToFunctionDeclaration(func); + } else { + const funcDeclar = Factory.createTSDeclarFunction( + name, + returnType, + params, + typeParameters, + generator, + isCurrentScopeParseAwaitAsExpression(), + start, + getLastTokenEndPositon(), + ); + shouldInsertSemi(); + exitFunctionScope(false); + return funcDeclar; + } } /** * Parse function maybe call by parseFunctionDeclaration and parseFunctionExpression, @@ -2185,7 +2284,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt // recoverable error raiseError(ErrorMessageMap.syntax_error_function_statement_requires_a_name, getStartPosition()); } - const typeParameters = tryParseTSTypeParameterDeclaration(); + const typeParameters = tryParseTSTypeParameterDeclaration(false); const params = parseFunctionParam(); return [name, typeParameters, params]; }); @@ -2237,10 +2336,10 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt * scope (function body). so there we need to implement special logical for parse function * name. and you need to note that name of function expression and name of function delcaration * have different context rule for parse function name. - * @param {boolean} isExpression + * @param {boolean} optionalName * @returns {Identifier | null} */ - function parseFunctionName(isExpression: boolean): Identifier | null { + function parseFunctionName(optionalName: boolean): Identifier | null { return parseWithLHSLayer(() => { let name: Identifier | null = null; // there we do not just using parseIdentifier function as the reason above @@ -2250,14 +2349,14 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } else { if (match(SyntaxKinds.AwaitKeyword)) { // for function expression, can await treat as function name is dep on current scope. - if (isExpression && isCurrentScopeParseAwaitAsExpression()) { + if (optionalName && isCurrentScopeParseAwaitAsExpression()) { raiseError( ErrorMessageMap.babel_error_can_not_use_await_as_identifier_inside_an_async_function, getStartPosition(), ); } // for function declaration, can await treat as function name is dep on parent scope. - if (!isExpression && isParentFunctionAsync()) { + if (!optionalName && isParentFunctionAsync()) { raiseError( ErrorMessageMap.babel_error_can_not_use_await_as_identifier_inside_an_async_function, getStartPosition(), @@ -2272,11 +2371,11 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt name = parseIdentifierName(); } else if (match(SyntaxKinds.YieldKeyword)) { // for function expression, can yield treat as function name is dep on current scope. - if (isExpression && isCurrentScopeParseYieldAsExpression()) { + if (optionalName && isCurrentScopeParseYieldAsExpression()) { raiseError(ErrorMessageMap.babel_error_invalid_yield, getStartPosition()); } // for function declaration, can yield treat as function name is dep on parent scope. - if (!isExpression && isParentFunctionGenerator()) { + if (!optionalName && isParentFunctionGenerator()) { raiseError(ErrorMessageMap.babel_error_invalid_yield, getStartPosition()); } // if in strict mode, yield can not be function name. @@ -2439,7 +2538,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt match(SyntaxKinds.BitwiseLeftShiftOperator) || match(SyntaxKinds.ParenthesesLeftPunctuator) ) { - const typeArguments = tryParseTSTypeParameterInstantiation(); + const typeArguments = tryParseTSTypeParameterInstantiation(false); const { nodes, end } = parseArguments(); const callExpr = Factory.createCallExpression( expr, @@ -2871,9 +2970,10 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt if ( !requirePlugin(ParserPlugin.JSX) && requirePlugin(ParserPlugin.TypeScript) && - match(SyntaxKinds.LtOperator) + (match(SyntaxKinds.LtOperator) || match(SyntaxKinds.BitwiseLeftShiftOperator)) ) { - return parseTSGenericArrowFunctionExpression(); + const expr = parseTSGenericArrowFunctionExpression(); + if (expr) return expr; } const [leftExpr, scope] = parseWithCatpureLayer(parseConditionalExpression); if (!match(AssigmentOperators)) { @@ -3008,9 +3108,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt if (shouldEarlyReturn(atom)) { return atom; } - if (match(BinaryOperators)) { - atom = parseBinaryOps(atom); - } + atom = parseBinaryOps(atom); if (isPrivateName(atom)) { raiseError(ErrorMessageMap.babel_error_private_name_wrong_used, atom.start); } @@ -3080,6 +3178,31 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt function parseBinaryOps(left: Expression, lastPre: number = 0): Expression { // eslint-disable-next-line no-constant-condition while (1) { + // TS handle + if ( + requirePlugin(ParserPlugin.TypeScript) && + (isContextKeyword("as") || isContextKeyword("satisfies")) + ) { + const isSatisfies = isContextKeyword("satisfies"); + nextToken(); + const typeNode = parseTSTypeNode(); + if (isSatisfies) { + left = Factory.createTSSatisfiesExpression( + left, + typeNode, + cloneSourcePosition(left.start), + getLastTokenEndPositon(), + ); + } else { + left = Factory.createTSAsExpression( + left, + typeNode, + cloneSourcePosition(left.start), + getLastTokenEndPositon(), + ); + } + continue; + } const currentOp = getToken(); if (!isBinaryOps(currentOp) || getBinaryPrecedence(currentOp) < lastPre) { break; @@ -3143,6 +3266,20 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt usePrivateName(privateName.name, privateName.start); return privateName; } + if ( + (match(SyntaxKinds.LtOperator) || match(SyntaxKinds.BitwiseLeftShiftOperator)) && + !requirePlugin(ParserPlugin.JSX) + ) { + const start = getStartPosition(); + const typeArguments = parseTSTypeParameterInstantiation(false); + const expression = parseUnaryExpression(); + return Factory.createTSTypeAssertionExpression( + expression, + typeArguments.params[0], + start, + getLastTokenEndPositon(), + ); + } return parseUnaryExpression(); } function parseUnaryExpression(): Expression { @@ -3251,6 +3388,19 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt }; while (!state.shouldStop) { state.optional = false; + if ( + requirePlugin(ParserPlugin.TypeScript) && + !getLineTerminatorFlag() && + match(SyntaxKinds.LogicalNOTOperator) + ) { + nextToken(); + base = Factory.createTSNonNullExpression( + base, + cloneSourcePosition(base.start), + getLastTokenEndPositon(), + ); + continue; + } if (state.abortLastTime) { base = parseLeftHandSideExpressionWithoutTypeArguments(base, state); } else { @@ -3271,7 +3421,8 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } function parseLeftHandSideExpressionWithTypeArguments(base: Expression, state: LefthansSideParseState) { parseQuestionDotOfLeftHandSideExpression(state); - const [typeArguments, abort] = parseTypeArgumentsOfLeftHandSideExpression(state); + const result = parseTypeArgumentsOfLeftHandSideExpression(state); + const [typeArguments, abort] = result; if (match(SyntaxKinds.ParenthesesLeftPunctuator)) { // callexpression base = parseCallExpression(base, state.optional, typeArguments); @@ -3365,7 +3516,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt let abort = () => {}; if (match(SyntaxKinds.LtOperator) || match(SyntaxKinds.BitwiseLeftShiftOperator)) { const result = tryParse(() => { - return tryParseTSTypeParameterInstantiation(); + return tryParseTSTypeParameterInstantiation(false); }); if (result) { typeArguments = result?.[0]; @@ -3374,7 +3525,9 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt errorhandler.restoreTryFail(result[3]); state.abortLastTime = true; }; + return [typeArguments, abort]; } + //return undefined; } return [typeArguments, abort]; } @@ -3384,7 +3537,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt * @returns */ function checkExpressionAsLeftValue(expression: ModuleItem) { - if (isIdentifer(expression) || isMemberExpression(expression)) { + if (isAssignable(expression)) { return; } raiseError(ErrorMessageMap.invalid_left_value, expression.start); @@ -3743,7 +3896,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt // - binary expression: `async < literal-item`. if (kind === SyntaxKinds.LtOperator) { const id = parseIdentifierReference(); - const typeParameterResult = tryParse(parseTSTypeParameterDeclaration); + const typeParameterResult = tryParse(() => parseTSTypeParameterDeclaration(false)); if (typeParameterResult) { // there const [ @@ -3766,7 +3919,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } abortTryParseResult(typeParameterResult[1], typeParameterResult[2], typeParameterResult[3]); } - const typeArgumentResult = tryParse(parseTSTypeParameterInstantiation); + const typeArgumentResult = tryParse(() => parseTSTypeParameterInstantiation(false)); if (typeArgumentResult) { const typeArguments = typeArgumentResult[0]; const callArguments = parseArguments().nodes; @@ -3785,7 +3938,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt if (kind === SyntaxKinds.BitwiseLeftShiftOperator) { const id = parseIdentifierReference(); lexer.reLexLtRelateToken(); - const typeArguments = parseTSTypeParameterInstantiation(); + const typeArguments = parseTSTypeParameterInstantiation(false); const callArguments = parseArguments().nodes; return Factory.createCallExpression( id, @@ -4349,7 +4502,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } function tryParseTSTypeParameterInstantiationForNewExpression() { if (match(SyntaxKinds.LtOperator) || match(SyntaxKinds.BitwiseLeftShiftOperator)) { - const result = tryParse(tryParseTSTypeParameterInstantiation); + const result = tryParse(() => tryParseTSTypeParameterInstantiation(false)); if ( match([ SyntaxKinds.ParenthesesLeftPunctuator, @@ -4418,7 +4571,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt // recoverable error raiseError(ErrorMessageMap.babel_error_call_super_outside_of_ctor, keywordStart); } - const typeArguments = tryParseTSTypeParameterInstantiation(); + const typeArguments = tryParseTSTypeParameterInstantiation(false); const { nodes, end: argusEnd } = parseArguments(); return Factory.createCallExpression( Factory.createSuper(keywordStart, keywordEnd), @@ -4851,7 +5004,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt raiseError(ErrorMessageMap.v8_error_a_class_may_only_have_one_constructor, propertyName.start); } } - const typeParameters = tryParseTSTypeParameterDeclaration(); + const typeParameters = tryParseTSTypeParameterDeclaration(false); enterFunctionScope(isAsync, generator); const [parmas, scope] = parseWithCatpureLayer(parseFunctionParam); const returnType = tryParseTSReturnTypeOrTypePredicate(SyntaxKinds.ColonPunctuator); @@ -6321,35 +6474,28 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt ); } case SyntaxKinds.FunctionKeyword: { - enterFunctionScope(); - const func = parseFunction(true); - exitFunctionScope(false); - const funcDeclar = Factory.transFormFunctionToFunctionDeclaration(func); + const funcDeclar = parseFunctionDeclaration(false, true); staticSematicForDuplicateDefaultExport(funcDeclar); - const name = funcDeclar.name; - if (name) { - delcarateFcuntionSymbol(name.name, func.generator, func.start); - } return Factory.createExportDefaultDeclaration(funcDeclar, start, cloneSourcePosition(funcDeclar.end)); } default: { if (isContextKeyword("async") && lookahead().kind === SyntaxKinds.FunctionKeyword) { nextToken(); - enterFunctionScope(true); - const func = parseFunction(true); - exitFunctionScope(false); - const funcDeclar = Factory.transFormFunctionToFunctionDeclaration(func); - funcDeclar.async = true; + const funcDeclar = parseFunctionDeclaration(true, true); + // funcDeclar.async = true; staticSematicForDuplicateDefaultExport(funcDeclar); - if (funcDeclar.name) { - delcarateFcuntionSymbol(funcDeclar.name.name, func.generator, func.start); - } return Factory.createExportDefaultDeclaration( funcDeclar, start, cloneSourcePosition(funcDeclar.end), ); } + const typeDeclar = tryParseDeclarationWithIdentifierStart(); + if (typeDeclar) { + shouldInsertSemi(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return Factory.createExportDefaultDeclaration(typeDeclar as any, start, getLastTokenEndPositon()); + } // TODO: parse export default from ""; (experimental feature) const expr = parseAssignmentExpressionAllowIn(); shouldInsertSemi(); @@ -6525,14 +6671,56 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt } return result; } + function parseTSEnumDeclaration(): TSEnumDeclaration { + const start = getStartPosition(); + nextToken(); // eat `enum` + const id = parseIdentifierReference(); + const body = parseTSEnumBody(); + return Factory.createTSEnumDeclaration(id, body, start, getLastTokenEndPositon()); + } + function parseTSEnumBody(): TSEnumBody { + const { start } = expect(SyntaxKinds.BracesLeftPunctuator); + const members = []; + let isStart = true; + while (!match([SyntaxKinds.BracesRightPunctuator, SyntaxKinds.EOFToken])) { + if (isStart) { + isStart = false; + } else { + expect(SyntaxKinds.CommaToken); + } + // allow trailing comma + if (match([SyntaxKinds.BracesRightPunctuator, SyntaxKinds.EOFToken])) { + break; + } + members.push(parseTSEnumMember()); + } + const { end } = expect(SyntaxKinds.BracesRightPunctuator); + return Factory.createTSEnumBody(members, start, end); + } + function parseTSEnumMember(): TSEnumMember { + const name = parseIdentifierName(); + let init: Expression | undefined = undefined; + if (match(SyntaxKinds.AssginOperator)) { + nextToken(); + init = parseAssignmentExpressionAllowIn(); + } + return Factory.createTSEnumMember( + name, + false, + init, + cloneSourcePosition(name.start), + getLastTokenEndPositon(), + ); + } function parseTSTypeAlias(): TSTypeAliasDeclaration { // TODO: TS garud const start = getStartPosition(); nextToken(); // eat `type` const name = parseIdentifierReference(); - const typeParameters = tryParseTSTypeParameterDeclaration(); + const typeParameters = tryParseTSTypeParameterDeclaration(true); expect(SyntaxKinds.AssginOperator); const typeNode = parseTSTypeNode(); + shouldInsertSemi(); return Factory.createTSTypeAliasDeclaration( name, typeNode, @@ -6546,24 +6734,48 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt const start = getStartPosition(); nextToken(); // eat `interface` const id = parseIdentifierReference(); - const typeParameters = tryParseTSTypeParameterDeclaration(); + const typeParameters = tryParseTSTypeParameterDeclaration(false); + const extendTypes = tryParseTSInterfaceDeclarationExtends(); const body = parseTSInterfaceBody(); - return Factory.createTSInterface(id, typeParameters, body, start, getLastTokenEndPositon()); + shouldInsertSemi(); + return Factory.createTSInterface(id, typeParameters, extendTypes, body, start, getLastTokenEndPositon()); + } + function tryParseTSInterfaceDeclarationExtends(): Array { + if (match(SyntaxKinds.ExtendsKeyword)) { + nextToken(); + const extendsInterfaces = [parseTSInterfaceHeritage()]; + while (match(SyntaxKinds.CommaToken)) { + nextToken(); + extendsInterfaces.push(parseTSInterfaceHeritage()); + } + return extendsInterfaces; + } + return []; + } + function parseTSInterfaceHeritage() { + const name = parseTSEntityName(); + const typeArguments = tryParseTSTypeParameterInstantiation(false); + return Factory.createTSInterfaceHeritage( + name, + typeArguments, + cloneSourcePosition(name.start), + getLastTokenEndPositon(), + ); } - function tryParseTSTypeParameterDeclaration() { + function tryParseTSTypeParameterDeclaration(allowAssign: boolean) { // TODO: TS garud if (match(SyntaxKinds.LtOperator)) { - return parseTSTypeParameterDeclaration(); + return parseTSTypeParameterDeclaration(allowAssign); } } - function parseTSTypeParameterDeclaration(): TSTypeParameterDeclaration { + function parseTSTypeParameterDeclaration(allowAssign: boolean): TSTypeParameterDeclaration { const { start } = expect(SyntaxKinds.LtOperator); const params = [parseTSTypeParameter()]; while (match(SyntaxKinds.CommaToken)) { nextToken(); params.push(parseTSTypeParameter()); } - parseGtTokenAsEndOfTypeParameters(); + parseGtTokenAsEndOfTypeParameters(allowAssign); return Factory.createTSTypeParameterDeclaration(params, start, getLastTokenEndPositon()); } function parseTSTypeParameter(): TSTypeParameter { @@ -6586,26 +6798,28 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt getLastTokenEndPositon(), ); } - function tryParseTSTypeParameterInstantiation(): TSTypeParameterInstantiation | undefined { + function tryParseTSTypeParameterInstantiation( + allowAssign: boolean, + ): TSTypeParameterInstantiation | undefined { if (match(SyntaxKinds.LtOperator)) { - return parseTSTypeParameterInstantiation(); + return parseTSTypeParameterInstantiation(allowAssign); } if (match(SyntaxKinds.BitwiseLeftShiftOperator)) { lexer.reLexLtRelateToken(); - return parseTSTypeParameterInstantiation(); + return parseTSTypeParameterInstantiation(allowAssign); } } - function parseTSTypeParameterInstantiation(): TSTypeParameterInstantiation { + function parseTSTypeParameterInstantiation(allowAssign: boolean): TSTypeParameterInstantiation { const { start } = expect(SyntaxKinds.LtOperator); const params = [parseTSTypeNode()]; while (match(SyntaxKinds.CommaToken)) { nextToken(); params.push(parseTSTypeNode()); } - parseGtTokenAsEndOfTypeParameters(); + parseGtTokenAsEndOfTypeParameters(allowAssign); return Factory.createTSTypeParameterInstantiation(params, start, getLastTokenEndPositon()); } - function parseGtTokenAsEndOfTypeParameters() { + function parseGtTokenAsEndOfTypeParameters(allowAssign: boolean) { if ( match([ SyntaxKinds.GeqtOperator, @@ -6615,7 +6829,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt SyntaxKinds.BitwiseRightShiftFillAssginOperator, ]) ) { - lexer.reLexGtRelateToken(); + lexer.reLexGtRelateToken(allowAssign); } expect(SyntaxKinds.GtOperator); } @@ -6690,33 +6904,43 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt getLastTokenEndPositon(), ); } - function parseTSGenericArrowFunctionExpression(): ArrorFunctionExpression { - const start = getStartPosition(); - const typeParameters = tryParseTSTypeParameterDeclaration(); - const [parmas, scope] = parseWithCatpureLayer(parseFunctionParam); - const returnType = tryParseTSReturnTypeOrTypePredicate(SyntaxKinds.ColonPunctuator); - expect(SyntaxKinds.ArrowOperator); - enterArrowFunctionBodyScope(true); - let body: Expression | FunctionBody; - let isExpression = false; - if (match(SyntaxKinds.BracesLeftPunctuator)) { - body = parseFunctionBody(); - } else { - body = parseAssignmentExpressionInheritIn(); - isExpression = true; + function parseTSGenericArrowFunctionExpression(): ArrorFunctionExpression | undefined { + const result = tryParse( + (): [ + TSTypeParameterDeclaration | undefined, + [ + ASTArrayWithMetaData & { + trailingComma: boolean; + typeAnnotations: Array<[TSTypeAnnotation | undefined, boolean]> | undefined; + }, + StrictModeScope, + AsyncArrowExpressionScope, + ], + TSTypeAnnotation | undefined, + ] => { + const typeParameters = tryParseTSTypeParameterDeclaration(false); + const [[meta, strictModeScope], arrowExprScope] = parseWithArrowExpressionScope(() => + parseWithCatpureLayer(parseArgumentsWithType), + ); + meta.start = typeParameters?.start || meta.start; + const returnType = tryParseTSReturnTypeOrTypePredicate(SyntaxKinds.ColonPunctuator); + return [typeParameters, [meta, strictModeScope, arrowExprScope], returnType]; + }, + ); + if (!result) { + return; } - postStaticSematicEarlyErrorForStrictModeOfFunction(null, scope); + const [[typeParameters, [meta, strictModeScope, arrowExprScope], returnType], state, context, index] = + result; + if (!match(SyntaxKinds.ArrowOperator)) { + abortTryParseResult(state, context, index); + return; + } + enterArrowFunctionBodyScope(); + const arrowExpr = parseArrowFunctionExpression(meta, typeParameters, strictModeScope, arrowExprScope); exitArrowFunctionBodyScope(); - return Factory.createArrowExpression( - isExpression, - body, - parmas, - typeParameters, - returnType, - isCurrentScopeParseAwaitAsExpression(), - start, - getLastTokenEndPositon(), - ); + arrowExpr.returnType = returnType; + return arrowExpr; } function isTSFunctionTypeStart() { if (match(SyntaxKinds.LtOperator)) { @@ -7039,7 +7263,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt function parseTSTypeReference(): TSTypeReference { // TODO: TS garud const typeName = parseTSEntityName(); - const typeArguments = tryParseTSTypeParameterInstantiation(); + const typeArguments = tryParseTSTypeParameterInstantiation(false); return Factory.createTSTypeReference( typeName, typeArguments, @@ -7062,7 +7286,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt return left; } function parseTSFunctionSingnature(expectToken: SyntaxKinds, optional: boolean) { - const typeParameters = tryParseTSTypeParameterDeclaration(); + const typeParameters = tryParseTSTypeParameterDeclaration(false); const parameters = parseInType(parseFunctionParam) as TSParameter[]; const matchToken = match(expectToken); if (optional && !matchToken) { @@ -7157,6 +7381,7 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt const members: Array = []; while (!match([SyntaxKinds.EOFToken, SyntaxKinds.BracesRightPunctuator])) { members.push(parseTSTypeElment()); + parseTSInterTypeElement(); } const { end } = expect(SyntaxKinds.BracesRightPunctuator); return { @@ -7171,13 +7396,15 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt const members: Array = []; while (!match([SyntaxKinds.EOFToken, SyntaxKinds.BracesRightPunctuator])) { members.push(parseTSTypeElment()); + parseTSInterTypeElement(); } const { end } = expect(SyntaxKinds.BracesRightPunctuator); return Factory.createTSInterfaceBody(members, start, end); } function parseTSTypeElment(): TSTypeElement { switch (getToken()) { - case SyntaxKinds.ParenthesesLeftPunctuator: { + case SyntaxKinds.ParenthesesLeftPunctuator: + case SyntaxKinds.LtOperator: { // TSCallSignatureDeclaration const start = getStartPosition(); const { parameters, returnType, typeParameters } = parseTSFunctionSingnature( @@ -7218,15 +7445,15 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt optional = true; nextToken(); } - if (match(SyntaxKinds.ParenthesesLeftPunctuator)) { + if (match(SyntaxKinds.ParenthesesLeftPunctuator) || match(SyntaxKinds.LtOperator)) { const { parameters, returnType, typeParameters } = parseTSFunctionSingnature( SyntaxKinds.ColonPunctuator, true, ); return Factory.createTSMethodSignature( key, - optional, isComputedRef.isComputed, + optional, parameters, returnType, typeParameters, @@ -7234,18 +7461,31 @@ export function createParser(code: string, errorhandler: SyntaxErrorHandler, opt getLastTokenEndPositon(), ); } - const typeAnnotation = parseTypeAnnoation(); + const typeAnnotation = tryParseTypeAnnotation(); return Factory.createTSPropertySignature( key, isComputedRef.isComputed, optional, typeAnnotation, cloneSourcePosition(key.start), - cloneSourcePosition(typeAnnotation.end), + getLastTokenEndPositon(), ); } } } + function parseTSInterTypeElement() { + if (match([SyntaxKinds.SemiPunctuator, SyntaxKinds.CommaToken])) { + nextToken(); + return; + } + if (match(SyntaxKinds.BracesRightPunctuator)) { + return; + } + if (getLineTerminatorFlag()) { + return; + } + // TODO: should error + } function tryParseTypeAnnotation(): TSTypeAnnotation | undefined { if (match(SyntaxKinds.ColonPunctuator)) { return parseTypeAnnoation(); diff --git a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/268/output.txt b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/268/output.txt index 8f246886..5b9ff1ba 100644 --- a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/268/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/268/output.txt @@ -1 +1,3 @@ -[Syntax Error]: Unexpect token DecimalLiteral(1, 14). \ No newline at end of file +[SyntaxError]: Missing semicolon or line terminator. (1,14) +1|function a() 1 // expression closure is not supported + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/368/output.txt b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/368/output.txt index f00b1369..977f0f09 100644 --- a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/368/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/368/output.txt @@ -1 +1 @@ -[Syntax Error]: Unexpect token enum(1, 1). \ No newline at end of file +[Syntax Error]: Unexpect token =(1, 6). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/369/output.txt b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/369/output.txt index f00b1369..977f0f09 100644 --- a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/369/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/369/output.txt @@ -1 +1 @@ -[Syntax Error]: Unexpect token enum(1, 1). \ No newline at end of file +[Syntax Error]: Unexpect token =(1, 6). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/388/output.txt b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/388/output.txt index 022f7b98..d9eeebde 100644 --- a/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/388/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2015/uncategorised/388/output.txt @@ -1 +1,6 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: 'import' and 'export' may appear only with 'sourceType: "module"' (1,1) +1|export function() {}; + |^ +[SyntaxError]: function statement requires a name (1,16) +1|export function() {}; + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export-async/output.txt b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export-async/output.txt index 2d7fbb0a..d10bc2e4 100644 --- a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export-async/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export-async/output.txt @@ -1 +1 @@ -[Unreach Zone]: this piece of code should not be reach (1, 8), have a unexpect token 10130 (async)., please report to developer. \ No newline at end of file +[Syntax Error]: Unexpect token Identifer(1, 8). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/input.js b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/input.js index 3f043e61..120136ec 100644 --- a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/input.js +++ b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/input.js @@ -1,2 +1,2 @@ export async function foo() {} -export default async function bar() {} +export default function bar() {} diff --git a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/output.json b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/output.json index d5a30cf7..189d49c3 100644 --- a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/output.json +++ b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/export/output.json @@ -69,41 +69,41 @@ "name": "bar", "start": { "row": 2, - "col": 31, - "index": 61 + "col": 25, + "index": 55 }, "end": { "row": 2, - "col": 34, - "index": 64 + "col": 28, + "index": 58 } }, "generator": false, - "async": true, + "async": false, "body": { "kind": "FunctionBody", "body": [], "start": { "row": 2, - "col": 37, - "index": 67 + "col": 31, + "index": 61 }, "end": { "row": 2, - "col": 39, - "index": 69 + "col": 33, + "index": 63 } }, "params": [], "start": { "row": 2, - "col": 22, - "index": 52 + "col": 16, + "index": 46 }, "end": { "row": 2, - "col": 39, - "index": 69 + "col": 33, + "index": 63 } }, "start": { @@ -113,8 +113,8 @@ }, "end": { "row": 2, - "col": 39, - "index": 69 + "col": 33, + "index": 63 } } ], @@ -126,6 +126,6 @@ "end": { "row": 3, "col": 1, - "index": 70 + "index": 64 } } \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-export-async-function/output.txt b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-export-async-function/output.txt index 4ac821f2..d10bc2e4 100644 --- a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-export-async-function/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-export-async-function/output.txt @@ -1,3 +1 @@ -[SyntaxError]: 'import' and 'export' may appear only with 'sourceType: "module"' (1,1) -1|export \u0061sync function y() { await x } - |^ +[Syntax Error]: Unexpect token Identifer(1, 8). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-sequence-function/output.txt b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-sequence-function/output.txt index 022f7b98..aca74b46 100644 --- a/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-sequence-function/output.txt +++ b/web-infras/parser/tests/fixtures/babel/es2017/async-functions/invalid-escape-sequence-function/output.txt @@ -1 +1,9 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: Missing semicolon or line terminator. (1,12) +1|\u0061sync function() { await x } + | ^ +[SyntaxError]: function statement requires a name (1,20) +1|\u0061sync function() { await x } + | ^ +[SyntaxError]: Missing semicolon or line terminator. (1,31) +1|\u0061sync function() { await x } + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-fragment/output.txt b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-fragment/output.txt index 15aa789a..de10bcb3 100644 --- a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-fragment/output.txt +++ b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-fragment/output.txt @@ -1,3 +1 @@ -[SyntaxError]: This experimental syntax requires enabling jsx plugins. (3,5) -3| <>Hello - | ^ +[Syntax Error]: Unexpect token >(3, 6). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-jsx-expression/output.txt b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-jsx-expression/output.txt index ad61d5fe..59476430 100644 --- a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-jsx-expression/output.txt +++ b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no-plugin-jsx-expression/output.txt @@ -1,3 +1 @@ -[SyntaxError]: This experimental syntax requires enabling jsx plugins. (1,1) -1|
{name}
- |^ +[Syntax Error]: Unexpect token JSXClosedTagStart(1, 12). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin-non-BMP-identifier/output.txt b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin-non-BMP-identifier/output.txt index 3f625f72..c7110acc 100644 --- a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin-non-BMP-identifier/output.txt +++ b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin-non-BMP-identifier/output.txt @@ -1,3 +1 @@ -[SyntaxError]: This experimental syntax requires enabling jsx plugins. (1,1) -1|< - |^ +[Syntax Error]: Unexpect token JSXClosedTagStart(3, 2). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin/output.txt b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin/output.txt index 07fa8bcc..4ca34740 100644 --- a/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin/output.txt +++ b/web-infras/parser/tests/fixtures/babel/jsx/errors/_no_plugin/output.txt @@ -1,3 +1 @@ -[SyntaxError]: This experimental syntax requires enabling jsx plugins. (1,1) -1|
- |^ +[Syntax Error]: Unexpect token JSXClosedTagStart(1, 6). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/input.ts new file mode 100644 index 00000000..5989d8d4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/input.ts @@ -0,0 +1,3 @@ +const assert1 = (value: unknown): asserts value is string => {} +const assert2 = (value: unknown): asserts value => {} +const assert3 = (value: unknown): asserts => {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/output.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/output.json new file mode 100644 index 00000000..ab691b57 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/arrow-function/output.json @@ -0,0 +1,511 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "assert1", + "optional": false, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "init": { + "kind": "ArrowFunctionExpression", + "expressionBody": false, + "async": false, + "arguments": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 32, + "index": 31 + } + }, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 32, + "index": 31 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 23, + "index": 22 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "value", + "start": { + "row": 1, + "col": 43, + "index": 42 + }, + "end": { + "row": 1, + "col": 48, + "index": 47 + } + }, + "asserts": true, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 1, + "col": 52, + "index": 51 + }, + "end": { + "row": 1, + "col": 58, + "index": 57 + } + }, + "start": { + "row": 1, + "col": 52, + "index": 51 + }, + "end": { + "row": 1, + "col": 58, + "index": 57 + } + }, + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 58, + "index": 57 + } + }, + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 58, + "index": 57 + } + }, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 1, + "col": 62, + "index": 61 + }, + "end": { + "row": 1, + "col": 64, + "index": 63 + } + }, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 64, + "index": 63 + } + }, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 64, + "index": 63 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 64, + "index": 63 + } + }, + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "assert2", + "optional": false, + "start": { + "row": 2, + "col": 7, + "index": 70 + }, + "end": { + "row": 2, + "col": 14, + "index": 77 + } + }, + "init": { + "kind": "ArrowFunctionExpression", + "expressionBody": false, + "async": false, + "arguments": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 2, + "col": 25, + "index": 88 + }, + "end": { + "row": 2, + "col": 32, + "index": 95 + } + }, + "start": { + "row": 2, + "col": 23, + "index": 86 + }, + "end": { + "row": 2, + "col": 32, + "index": 95 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 18, + "index": 81 + }, + "end": { + "row": 2, + "col": 23, + "index": 86 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "value", + "start": { + "row": 2, + "col": 43, + "index": 106 + }, + "end": { + "row": 2, + "col": 48, + "index": 111 + } + }, + "asserts": true, + "start": { + "row": 2, + "col": 33, + "index": 96 + }, + "end": { + "row": 2, + "col": 48, + "index": 111 + } + }, + "start": { + "row": 2, + "col": 33, + "index": 96 + }, + "end": { + "row": 2, + "col": 48, + "index": 111 + } + }, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 2, + "col": 52, + "index": 115 + }, + "end": { + "row": 2, + "col": 54, + "index": 117 + } + }, + "start": { + "row": 2, + "col": 17, + "index": 80 + }, + "end": { + "row": 2, + "col": 54, + "index": 117 + } + }, + "start": { + "row": 2, + "col": 7, + "index": 70 + }, + "end": { + "row": 2, + "col": 54, + "index": 117 + } + } + ], + "start": { + "row": 2, + "col": 1, + "index": 64 + }, + "end": { + "row": 2, + "col": 54, + "index": 117 + } + }, + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "assert3", + "optional": false, + "start": { + "row": 3, + "col": 7, + "index": 124 + }, + "end": { + "row": 3, + "col": 14, + "index": 131 + } + }, + "init": { + "kind": "ArrowFunctionExpression", + "expressionBody": false, + "async": false, + "arguments": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 3, + "col": 25, + "index": 142 + }, + "end": { + "row": 3, + "col": 32, + "index": 149 + } + }, + "start": { + "row": 3, + "col": 23, + "index": 140 + }, + "end": { + "row": 3, + "col": 32, + "index": 149 + } + }, + "optional": false, + "start": { + "row": 3, + "col": 18, + "index": 135 + }, + "end": { + "row": 3, + "col": 23, + "index": 140 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "asserts", + "start": { + "row": 3, + "col": 35, + "index": 152 + }, + "end": { + "row": 3, + "col": 42, + "index": 159 + } + }, + "start": { + "row": 3, + "col": 35, + "index": 152 + }, + "end": { + "row": 3, + "col": 42, + "index": 159 + } + }, + "start": { + "row": 3, + "col": 33, + "index": 150 + }, + "end": { + "row": 3, + "col": 42, + "index": 159 + } + }, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 3, + "col": 46, + "index": 163 + }, + "end": { + "row": 3, + "col": 48, + "index": 165 + } + }, + "start": { + "row": 3, + "col": 17, + "index": 134 + }, + "end": { + "row": 3, + "col": 48, + "index": 165 + } + }, + "start": { + "row": 3, + "col": 7, + "index": 124 + }, + "end": { + "row": 3, + "col": 48, + "index": 165 + } + } + ], + "start": { + "row": 3, + "col": 1, + "index": 118 + }, + "end": { + "row": 3, + "col": 48, + "index": 165 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 166 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/input.ts new file mode 100644 index 00000000..0bb18752 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/input.ts @@ -0,0 +1,4 @@ +class C { + assertIsString(value: unknown): asserts value is string {} +} + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/output.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/output.json new file mode 100644 index 00000000..5241f7ef --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/asserts-var-with-predicate/output.json @@ -0,0 +1,215 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ClassDeclaration", + "id": { + "kind": "Identifer", + "name": "C", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "superClass": null, + "body": { + "kind": "ClassBody", + "body": [ + { + "kind": "ClassMethodDefinition", + "async": false, + "generator": false, + "computed": false, + "static": false, + "key": { + "kind": "Identifer", + "name": "assertIsString", + "start": { + "row": 2, + "col": 5, + "index": 14 + }, + "end": { + "row": 2, + "col": 19, + "index": 28 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 2, + "col": 27, + "index": 36 + }, + "end": { + "row": 2, + "col": 34, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 25, + "index": 34 + }, + "end": { + "row": 2, + "col": 34, + "index": 43 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 20, + "index": 29 + }, + "end": { + "row": 2, + "col": 25, + "index": 34 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "value", + "start": { + "row": 2, + "col": 45, + "index": 54 + }, + "end": { + "row": 2, + "col": 50, + "index": 59 + } + }, + "asserts": true, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 54, + "index": 63 + }, + "end": { + "row": 2, + "col": 60, + "index": 69 + } + }, + "start": { + "row": 2, + "col": 54, + "index": 63 + }, + "end": { + "row": 2, + "col": 60, + "index": 69 + } + }, + "start": { + "row": 2, + "col": 35, + "index": 44 + }, + "end": { + "row": 2, + "col": 60, + "index": 69 + } + }, + "start": { + "row": 2, + "col": 35, + "index": 44 + }, + "end": { + "row": 2, + "col": 60, + "index": 69 + } + }, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 2, + "col": 61, + "index": 70 + }, + "end": { + "row": 2, + "col": 63, + "index": 72 + } + }, + "decorators": null, + "start": { + "row": 2, + "col": 5, + "index": 14 + }, + "end": { + "row": 2, + "col": 63, + "index": 72 + } + } + ], + "start": { + "row": 1, + "col": 9, + "index": 8 + }, + "end": { + "row": 3, + "col": 2, + "index": 74 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 74 + }, + "decorators": null + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 3, + "index": 77 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/input.ts new file mode 100644 index 00000000..404da1ba --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/input.ts @@ -0,0 +1,2 @@ +function assert(condition: any): +asserts condition {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/output.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/output.json new file mode 100644 index 00000000..0f866e7e --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration-with-line-break/output.json @@ -0,0 +1,142 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "assert", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 16, + "index": 15 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 2, + "col": 19, + "index": 51 + }, + "end": { + "row": 2, + "col": 21, + "index": 53 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "condition", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 1, + "col": 28, + "index": 27 + }, + "end": { + "row": 1, + "col": 31, + "index": 30 + } + }, + "start": { + "row": 1, + "col": 26, + "index": 25 + }, + "end": { + "row": 1, + "col": 31, + "index": 30 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "condition", + "start": { + "row": 2, + "col": 9, + "index": 41 + }, + "end": { + "row": 2, + "col": 18, + "index": 50 + } + }, + "asserts": true, + "start": { + "row": 1, + "col": 32, + "index": 31 + }, + "end": { + "row": 2, + "col": 18, + "index": 50 + } + }, + "start": { + "row": 1, + "col": 32, + "index": 31 + }, + "end": { + "row": 2, + "col": 18, + "index": 50 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 21, + "index": 53 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 54 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/input.ts new file mode 100644 index 00000000..b04da834 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/input.ts @@ -0,0 +1,3 @@ +function asserts1 (value: unknown): asserts value is string {} +function asserts2 (value: unknown): asserts value {} +function asserts3 (value: unknown): asserts {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/output.json b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/output.json new file mode 100644 index 00000000..0fecc8f6 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/assert-predicate/function-declaration/output.json @@ -0,0 +1,421 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "asserts1", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 1, + "col": 61, + "index": 60 + }, + "end": { + "row": 1, + "col": 63, + "index": 62 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 1, + "col": 27, + "index": 26 + }, + "end": { + "row": 1, + "col": 34, + "index": 33 + } + }, + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 34, + "index": 33 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 25, + "index": 24 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "value", + "start": { + "row": 1, + "col": 45, + "index": 44 + }, + "end": { + "row": 1, + "col": 50, + "index": 49 + } + }, + "asserts": true, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 1, + "col": 54, + "index": 53 + }, + "end": { + "row": 1, + "col": 60, + "index": 59 + } + }, + "start": { + "row": 1, + "col": 54, + "index": 53 + }, + "end": { + "row": 1, + "col": 60, + "index": 59 + } + }, + "start": { + "row": 1, + "col": 35, + "index": 34 + }, + "end": { + "row": 1, + "col": 60, + "index": 59 + } + }, + "start": { + "row": 1, + "col": 35, + "index": 34 + }, + "end": { + "row": 1, + "col": 60, + "index": 59 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 63, + "index": 62 + } + }, + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "asserts2", + "start": { + "row": 2, + "col": 10, + "index": 73 + }, + "end": { + "row": 2, + "col": 18, + "index": 81 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 2, + "col": 51, + "index": 114 + }, + "end": { + "row": 2, + "col": 53, + "index": 116 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 2, + "col": 27, + "index": 90 + }, + "end": { + "row": 2, + "col": 34, + "index": 97 + } + }, + "start": { + "row": 2, + "col": 25, + "index": 88 + }, + "end": { + "row": 2, + "col": 34, + "index": 97 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 20, + "index": 83 + }, + "end": { + "row": 2, + "col": 25, + "index": 88 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "value", + "start": { + "row": 2, + "col": 45, + "index": 108 + }, + "end": { + "row": 2, + "col": 50, + "index": 113 + } + }, + "asserts": true, + "start": { + "row": 2, + "col": 35, + "index": 98 + }, + "end": { + "row": 2, + "col": 50, + "index": 113 + } + }, + "start": { + "row": 2, + "col": 35, + "index": 98 + }, + "end": { + "row": 2, + "col": 50, + "index": 113 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 64 + }, + "end": { + "row": 2, + "col": 53, + "index": 116 + } + }, + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "asserts3", + "start": { + "row": 3, + "col": 10, + "index": 126 + }, + "end": { + "row": 3, + "col": 18, + "index": 134 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 3, + "col": 45, + "index": 161 + }, + "end": { + "row": 3, + "col": 47, + "index": 163 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "value", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSUnknowKeyword", + "start": { + "row": 3, + "col": 27, + "index": 143 + }, + "end": { + "row": 3, + "col": 34, + "index": 150 + } + }, + "start": { + "row": 3, + "col": 25, + "index": 141 + }, + "end": { + "row": 3, + "col": 34, + "index": 150 + } + }, + "optional": false, + "start": { + "row": 3, + "col": 20, + "index": 136 + }, + "end": { + "row": 3, + "col": 25, + "index": 141 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "asserts", + "start": { + "row": 3, + "col": 37, + "index": 153 + }, + "end": { + "row": 3, + "col": 44, + "index": 160 + } + }, + "start": { + "row": 3, + "col": 37, + "index": 153 + }, + "end": { + "row": 3, + "col": 44, + "index": 160 + } + }, + "start": { + "row": 3, + "col": 35, + "index": 151 + }, + "end": { + "row": 3, + "col": 44, + "index": 160 + } + }, + "start": { + "row": 3, + "col": 1, + "index": 117 + }, + "end": { + "row": 3, + "col": 47, + "index": 163 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 164 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/input.ts new file mode 100644 index 00000000..746078a2 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/input.ts @@ -0,0 +1 @@ +async (a as T) => {}; \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/output.txt new file mode 100644 index 00000000..a2761756 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-as/output.txt @@ -0,0 +1 @@ +[Syntax Error]: invalid assignment left-hand side (1, 19) \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/input.ts new file mode 100644 index 00000000..5e3f1481 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/input.ts @@ -0,0 +1 @@ +async ( a) => {}; \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/output.txt new file mode 100644 index 00000000..237c4223 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-async-parameter-assertion/output.txt @@ -0,0 +1 @@ +[Syntax Error]: invalid assignment left-hand side (1, 18) \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/input.ts new file mode 100644 index 00000000..f9f64497 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/input.ts @@ -0,0 +1 @@ +var asserted1 = ((n) => { return n; }); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/output.json new file mode 100644 index 00000000..3accb901 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-in-parens/output.json @@ -0,0 +1,160 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "VariableDeclaration", + "variant": "var", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "asserted1", + "optional": false, + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "init": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "ArrowFunctionExpression", + "expressionBody": false, + "async": false, + "arguments": [ + { + "kind": "Identifer", + "name": "n", + "optional": false, + "start": { + "row": 1, + "col": 24, + "index": 23 + }, + "end": { + "row": 1, + "col": 25, + "index": 24 + } + } + ], + "body": { + "kind": "FunctionBody", + "body": [ + { + "kind": "ReturnStatement", + "argu": { + "kind": "Identifer", + "name": "n", + "start": { + "row": 1, + "col": 39, + "index": 38 + }, + "end": { + "row": 1, + "col": 40, + "index": 39 + } + }, + "start": { + "row": 1, + "col": 32, + "index": 31 + }, + "end": { + "row": 1, + "col": 40, + "index": 39 + } + } + ], + "start": { + "row": 1, + "col": 30, + "index": 29 + }, + "end": { + "row": 1, + "col": 43, + "index": 42 + } + }, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 43, + "index": 42 + }, + "parentheses": true + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 44, + "index": 43 + } + }, + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 44, + "index": 43 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 44, + "index": 43 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 45 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/input.ts new file mode 100644 index 00000000..dc2282c6 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/input.ts @@ -0,0 +1 @@ +(a as T) => {}; \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/output.txt new file mode 100644 index 00000000..703cb79b --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-as/output.txt @@ -0,0 +1 @@ +[Syntax Error]: invalid assignment left-hand side (1, 13) \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/input.ts new file mode 100644 index 00000000..39dae7d0 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/input.ts @@ -0,0 +1 @@ +( a) => {}; \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/output.txt new file mode 100644 index 00000000..b9bcb6e2 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/arrow-parameter-assertion/output.txt @@ -0,0 +1 @@ +[Syntax Error]: invalid assignment left-hand side (1, 12) \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/as/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/as/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/input.ts new file mode 100644 index 00000000..3d6627d1 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/input.ts @@ -0,0 +1,6 @@ +x as T; +x < y as boolean; // (x < y) as boolean; +x as boolean <= y; // (x as boolean) <= y; +x === 1 as number; // x === (1 as number); +x as any as T; +x as boolean ?? y; // (x as boolean) ?? y; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/as/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/output.json new file mode 100644 index 00000000..96f11b57 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/as/output.json @@ -0,0 +1,499 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSAsExpression", + "expression": { + "kind": "BinaryExpression", + "operator": "<", + "left": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 1, + "index": 8 + }, + "end": { + "row": 2, + "col": 2, + "index": 9 + } + }, + "right": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 2, + "col": 5, + "index": 12 + }, + "end": { + "row": 2, + "col": 6, + "index": 13 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 8 + }, + "end": { + "row": 2, + "col": 6, + "index": 13 + } + }, + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 2, + "col": 10, + "index": 17 + }, + "end": { + "row": 2, + "col": 17, + "index": 24 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 8 + }, + "end": { + "row": 2, + "col": 17, + "index": 24 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 8 + }, + "end": { + "row": 2, + "col": 17, + "index": 24 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "<=", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 3, + "col": 1, + "index": 49 + }, + "end": { + "row": 3, + "col": 2, + "index": 50 + } + }, + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 3, + "col": 6, + "index": 54 + }, + "end": { + "row": 3, + "col": 13, + "index": 61 + } + }, + "start": { + "row": 3, + "col": 1, + "index": 49 + }, + "end": { + "row": 3, + "col": 13, + "index": 61 + } + }, + "right": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 3, + "col": 17, + "index": 65 + }, + "end": { + "row": 3, + "col": 18, + "index": 66 + } + }, + "start": { + "row": 3, + "col": 1, + "index": 49 + }, + "end": { + "row": 3, + "col": 18, + "index": 66 + } + }, + "start": { + "row": 3, + "col": 1, + "index": 49 + }, + "end": { + "row": 3, + "col": 18, + "index": 66 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSAsExpression", + "expression": { + "kind": "BinaryExpression", + "operator": "===", + "left": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 4, + "col": 1, + "index": 92 + }, + "end": { + "row": 4, + "col": 2, + "index": 93 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 4, + "col": 7, + "index": 98 + }, + "end": { + "row": 4, + "col": 8, + "index": 99 + } + }, + "start": { + "row": 4, + "col": 1, + "index": 92 + }, + "end": { + "row": 4, + "col": 8, + "index": 99 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 4, + "col": 12, + "index": 103 + }, + "end": { + "row": 4, + "col": 18, + "index": 109 + } + }, + "start": { + "row": 4, + "col": 1, + "index": 92 + }, + "end": { + "row": 4, + "col": 18, + "index": 109 + } + }, + "start": { + "row": 4, + "col": 1, + "index": 92 + }, + "end": { + "row": 4, + "col": 18, + "index": 109 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSAsExpression", + "expression": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 5, + "col": 1, + "index": 135 + }, + "end": { + "row": 5, + "col": 2, + "index": 136 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 5, + "col": 6, + "index": 140 + }, + "end": { + "row": 5, + "col": 9, + "index": 143 + } + }, + "start": { + "row": 5, + "col": 1, + "index": 135 + }, + "end": { + "row": 5, + "col": 9, + "index": 143 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 5, + "col": 13, + "index": 147 + }, + "end": { + "row": 5, + "col": 14, + "index": 148 + } + }, + "start": { + "row": 5, + "col": 13, + "index": 147 + }, + "end": { + "row": 5, + "col": 14, + "index": 148 + } + }, + "start": { + "row": 5, + "col": 1, + "index": 135 + }, + "end": { + "row": 5, + "col": 14, + "index": 148 + } + }, + "start": { + "row": 5, + "col": 1, + "index": 135 + }, + "end": { + "row": 5, + "col": 14, + "index": 148 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "??", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 6, + "col": 1, + "index": 150 + }, + "end": { + "row": 6, + "col": 2, + "index": 151 + } + }, + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 6, + "col": 6, + "index": 155 + }, + "end": { + "row": 6, + "col": 13, + "index": 162 + } + }, + "start": { + "row": 6, + "col": 1, + "index": 150 + }, + "end": { + "row": 6, + "col": 13, + "index": 162 + } + }, + "right": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 6, + "col": 17, + "index": 166 + }, + "end": { + "row": 6, + "col": 18, + "index": 167 + } + }, + "start": { + "row": 6, + "col": 1, + "index": 150 + }, + "end": { + "row": 6, + "col": 18, + "index": 167 + } + }, + "start": { + "row": 6, + "col": 1, + "index": 150 + }, + "end": { + "row": 6, + "col": 18, + "index": 167 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 7, + "col": 1, + "index": 193 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/input.ts new file mode 100644 index 00000000..1e4413d4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/input.ts @@ -0,0 +1,2 @@ +(a as number) = 42; +({ a: (b as any) = 2000 } = x); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/output.json new file mode 100644 index 00000000..e0a4e496 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/assert-and-assign/output.json @@ -0,0 +1,251 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + }, + "parentheses": true + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "42", + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 19, + "index": 18 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 19, + "index": 18 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 19, + "index": 18 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ObjectPattern", + "properties": [ + { + "kind": "ObjectPatternProperty", + "computed": false, + "shorted": false, + "key": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 2, + "col": 4, + "index": 23 + }, + "end": { + "row": 2, + "col": 5, + "index": 24 + } + }, + "value": { + "kind": "AssigmentPattern", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 2, + "col": 8, + "index": 27 + }, + "end": { + "row": 2, + "col": 9, + "index": 28 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 2, + "col": 13, + "index": 32 + }, + "end": { + "row": 2, + "col": 16, + "index": 35 + } + }, + "start": { + "row": 2, + "col": 8, + "index": 27 + }, + "end": { + "row": 2, + "col": 16, + "index": 35 + }, + "parentheses": true + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "2000", + "start": { + "row": 2, + "col": 20, + "index": 39 + }, + "end": { + "row": 2, + "col": 24, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 8, + "index": 27 + }, + "end": { + "row": 2, + "col": 24, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 4, + "index": 23 + }, + "end": { + "row": 2, + "col": 24, + "index": 43 + } + } + ], + "start": { + "row": 2, + "col": 2, + "index": 21 + }, + "end": { + "row": 2, + "col": 26, + "index": 45 + } + }, + "right": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 29, + "index": 48 + }, + "end": { + "row": 2, + "col": 30, + "index": 49 + } + }, + "start": { + "row": 2, + "col": 2, + "index": 21 + }, + "end": { + "row": 2, + "col": 30, + "index": 49 + }, + "parentheses": true + }, + "start": { + "row": 2, + "col": 2, + "index": 21 + }, + "end": { + "row": 2, + "col": 30, + "index": 49 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 3, + "col": 1, + "index": 52 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/input.ts new file mode 100644 index 00000000..ece9096f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/input.ts @@ -0,0 +1,2 @@ +[a as number] = [42]; +[a] = [42]; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/output.json new file mode 100644 index 00000000..19a76a57 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructure-and-assign/output.json @@ -0,0 +1,239 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "right": { + "kind": "ArrayExpression", + "elements": [ + { + "kind": "DecimalLiteral", + "rawValue": "42", + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "trailingComma": false, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 2, + "col": 10, + "index": 31 + }, + "end": { + "row": 2, + "col": 11, + "index": 32 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 3, + "index": 24 + }, + "end": { + "row": 2, + "col": 9, + "index": 30 + } + }, + "start": { + "row": 2, + "col": 2, + "index": 23 + }, + "end": { + "row": 2, + "col": 11, + "index": 32 + } + } + ], + "start": { + "row": 2, + "col": 1, + "index": 22 + }, + "end": { + "row": 2, + "col": 12, + "index": 33 + } + }, + "right": { + "kind": "ArrayExpression", + "elements": [ + { + "kind": "DecimalLiteral", + "rawValue": "42", + "start": { + "row": 2, + "col": 16, + "index": 37 + }, + "end": { + "row": 2, + "col": 18, + "index": 39 + } + } + ], + "trailingComma": false, + "start": { + "row": 2, + "col": 15, + "index": 36 + }, + "end": { + "row": 2, + "col": 19, + "index": 40 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 22 + }, + "end": { + "row": 2, + "col": 19, + "index": 40 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 22 + }, + "end": { + "row": 2, + "col": 19, + "index": 40 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 42 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/input.ts new file mode 100644 index 00000000..3946f7f0 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/input.ts @@ -0,0 +1,5 @@ +0, { ...{} as T} = b; +[...[] as T] = b; + +0, { ...({} as T)} = b; +[...([] as T)] = b; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/output.txt new file mode 100644 index 00000000..dd81d85a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignent-rest-invalid/output.txt @@ -0,0 +1,12 @@ +[SyntaxError]: `...` must be followed by an assignable reference in assignment contexts (1,9) +1|0, { ...{} as T} = b; + | ^ +[SyntaxError]: Invalid parenthesized assignment pattern. (4,10) +4|0, { ...({} as T)} = b; + | ^ +[SyntaxError]: `...` must be followed by an assignable reference in assignment contexts (4,10) +4|0, { ...({} as T)} = b; + | ^ +[SyntaxError]: Invalid parenthesized assignment pattern. (5,6) +5|[...([] as T)] = b; + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/input.ts new file mode 100644 index 00000000..bd876102 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/input.ts @@ -0,0 +1,7 @@ +({a: x as T} = b); +([a as T] = b); +({a: (x as T) = c} = b); +([(a as T) = c] = b); +({ ...a as T} = b); +([...a as T] = b); +({...x!} = y); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/output.json new file mode 100644 index 00000000..590474b1 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/destructuring-assignment-in-parens/output.json @@ -0,0 +1,918 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ObjectPattern", + "properties": [ + { + "kind": "ObjectPatternProperty", + "computed": false, + "shorted": false, + "key": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 4, + "index": 3 + } + }, + "value": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + }, + "parentheses": true + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 2, + "col": 3, + "index": 21 + }, + "end": { + "row": 2, + "col": 4, + "index": 22 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 2, + "col": 8, + "index": 26 + }, + "end": { + "row": 2, + "col": 9, + "index": 27 + } + }, + "start": { + "row": 2, + "col": 8, + "index": 26 + }, + "end": { + "row": 2, + "col": 9, + "index": 27 + } + }, + "start": { + "row": 2, + "col": 3, + "index": 21 + }, + "end": { + "row": 2, + "col": 9, + "index": 27 + } + } + ], + "start": { + "row": 2, + "col": 2, + "index": 20 + }, + "end": { + "row": 2, + "col": 10, + "index": 28 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 2, + "col": 13, + "index": 31 + }, + "end": { + "row": 2, + "col": 14, + "index": 32 + } + }, + "start": { + "row": 2, + "col": 2, + "index": 20 + }, + "end": { + "row": 2, + "col": 14, + "index": 32 + }, + "parentheses": true + }, + "start": { + "row": 2, + "col": 2, + "index": 20 + }, + "end": { + "row": 2, + "col": 14, + "index": 32 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ObjectPattern", + "properties": [ + { + "kind": "ObjectPatternProperty", + "computed": false, + "shorted": false, + "key": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 3, + "col": 3, + "index": 37 + }, + "end": { + "row": 3, + "col": 4, + "index": 38 + } + }, + "value": { + "kind": "AssigmentPattern", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 3, + "col": 7, + "index": 41 + }, + "end": { + "row": 3, + "col": 8, + "index": 42 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 3, + "col": 12, + "index": 46 + }, + "end": { + "row": 3, + "col": 13, + "index": 47 + } + }, + "start": { + "row": 3, + "col": 12, + "index": 46 + }, + "end": { + "row": 3, + "col": 13, + "index": 47 + } + }, + "start": { + "row": 3, + "col": 7, + "index": 41 + }, + "end": { + "row": 3, + "col": 13, + "index": 47 + }, + "parentheses": true + }, + "right": { + "kind": "Identifer", + "name": "c", + "start": { + "row": 3, + "col": 17, + "index": 51 + }, + "end": { + "row": 3, + "col": 18, + "index": 52 + } + }, + "start": { + "row": 3, + "col": 7, + "index": 41 + }, + "end": { + "row": 3, + "col": 18, + "index": 52 + } + }, + "start": { + "row": 3, + "col": 3, + "index": 37 + }, + "end": { + "row": 3, + "col": 18, + "index": 52 + } + } + ], + "start": { + "row": 3, + "col": 2, + "index": 36 + }, + "end": { + "row": 3, + "col": 19, + "index": 53 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 3, + "col": 22, + "index": 56 + }, + "end": { + "row": 3, + "col": 23, + "index": 57 + } + }, + "start": { + "row": 3, + "col": 2, + "index": 36 + }, + "end": { + "row": 3, + "col": 23, + "index": 57 + }, + "parentheses": true + }, + "start": { + "row": 3, + "col": 2, + "index": 36 + }, + "end": { + "row": 3, + "col": 23, + "index": 57 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "AssigmentPattern", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 4, + "col": 4, + "index": 63 + }, + "end": { + "row": 4, + "col": 5, + "index": 64 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 4, + "col": 9, + "index": 68 + }, + "end": { + "row": 4, + "col": 10, + "index": 69 + } + }, + "start": { + "row": 4, + "col": 9, + "index": 68 + }, + "end": { + "row": 4, + "col": 10, + "index": 69 + } + }, + "start": { + "row": 4, + "col": 4, + "index": 63 + }, + "end": { + "row": 4, + "col": 10, + "index": 69 + }, + "parentheses": true + }, + "right": { + "kind": "Identifer", + "name": "c", + "start": { + "row": 4, + "col": 14, + "index": 73 + }, + "end": { + "row": 4, + "col": 15, + "index": 74 + } + }, + "start": { + "row": 4, + "col": 4, + "index": 63 + }, + "end": { + "row": 4, + "col": 15, + "index": 74 + } + } + ], + "start": { + "row": 4, + "col": 2, + "index": 61 + }, + "end": { + "row": 4, + "col": 16, + "index": 75 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 4, + "col": 19, + "index": 78 + }, + "end": { + "row": 4, + "col": 20, + "index": 79 + } + }, + "start": { + "row": 4, + "col": 2, + "index": 61 + }, + "end": { + "row": 4, + "col": 20, + "index": 79 + }, + "parentheses": true + }, + "start": { + "row": 4, + "col": 2, + "index": 61 + }, + "end": { + "row": 4, + "col": 20, + "index": 79 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ObjectPattern", + "properties": [ + { + "kind": "RestElement", + "argument": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 5, + "col": 7, + "index": 88 + }, + "end": { + "row": 5, + "col": 8, + "index": 89 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 5, + "col": 12, + "index": 93 + }, + "end": { + "row": 5, + "col": 13, + "index": 94 + } + }, + "start": { + "row": 5, + "col": 12, + "index": 93 + }, + "end": { + "row": 5, + "col": 13, + "index": 94 + } + }, + "start": { + "row": 5, + "col": 7, + "index": 88 + }, + "end": { + "row": 5, + "col": 13, + "index": 94 + } + }, + "start": { + "row": 5, + "col": 4, + "index": 85 + }, + "end": { + "row": 5, + "col": 13, + "index": 94 + } + } + ], + "start": { + "row": 5, + "col": 2, + "index": 83 + }, + "end": { + "row": 5, + "col": 14, + "index": 95 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 5, + "col": 17, + "index": 98 + }, + "end": { + "row": 5, + "col": 18, + "index": 99 + } + }, + "start": { + "row": 5, + "col": 2, + "index": 83 + }, + "end": { + "row": 5, + "col": 18, + "index": 99 + }, + "parentheses": true + }, + "start": { + "row": 5, + "col": 2, + "index": 83 + }, + "end": { + "row": 5, + "col": 18, + "index": 99 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "RestElement", + "argument": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 6, + "col": 6, + "index": 107 + }, + "end": { + "row": 6, + "col": 7, + "index": 108 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 6, + "col": 11, + "index": 112 + }, + "end": { + "row": 6, + "col": 12, + "index": 113 + } + }, + "start": { + "row": 6, + "col": 11, + "index": 112 + }, + "end": { + "row": 6, + "col": 12, + "index": 113 + } + }, + "start": { + "row": 6, + "col": 6, + "index": 107 + }, + "end": { + "row": 6, + "col": 12, + "index": 113 + } + }, + "start": { + "row": 6, + "col": 3, + "index": 104 + }, + "end": { + "row": 6, + "col": 12, + "index": 113 + } + } + ], + "start": { + "row": 6, + "col": 2, + "index": 103 + }, + "end": { + "row": 6, + "col": 13, + "index": 114 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 6, + "col": 16, + "index": 117 + }, + "end": { + "row": 6, + "col": 17, + "index": 118 + } + }, + "start": { + "row": 6, + "col": 2, + "index": 103 + }, + "end": { + "row": 6, + "col": 17, + "index": 118 + }, + "parentheses": true + }, + "start": { + "row": 6, + "col": 2, + "index": 103 + }, + "end": { + "row": 6, + "col": 17, + "index": 118 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ObjectPattern", + "properties": [ + { + "kind": "RestElement", + "argument": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 7, + "col": 6, + "index": 126 + }, + "end": { + "row": 7, + "col": 7, + "index": 127 + } + }, + "start": { + "row": 7, + "col": 6, + "index": 126 + }, + "end": { + "row": 7, + "col": 8, + "index": 128 + } + }, + "start": { + "row": 7, + "col": 3, + "index": 123 + }, + "end": { + "row": 7, + "col": 8, + "index": 128 + } + } + ], + "start": { + "row": 7, + "col": 2, + "index": 122 + }, + "end": { + "row": 7, + "col": 9, + "index": 129 + } + }, + "right": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 7, + "col": 12, + "index": 132 + }, + "end": { + "row": 7, + "col": 13, + "index": 133 + } + }, + "start": { + "row": 7, + "col": 2, + "index": 122 + }, + "end": { + "row": 7, + "col": 13, + "index": 133 + }, + "parentheses": true + }, + "start": { + "row": 7, + "col": 2, + "index": 122 + }, + "end": { + "row": 7, + "col": 13, + "index": 133 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 8, + "col": 1, + "index": 136 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/input.ts new file mode 100644 index 00000000..51f9677f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/input.ts @@ -0,0 +1 @@ +f(x < 0, /a/); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/output.json new file mode 100644 index 00000000..29dbb503 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/false-positive/output.json @@ -0,0 +1,115 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "CallExpression", + "optional": false, + "callee": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "arguments": [ + { + "kind": "BinaryExpression", + "operator": "<", + "left": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 4, + "index": 3 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "0", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + { + "kind": "RegexLiteral", + "pattern": "a", + "flag": "", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 15 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/input.ts new file mode 100644 index 00000000..63549667 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/input.ts @@ -0,0 +1,2 @@ +for (a as T of []); +for ( a of []); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/output.json new file mode 100644 index 00000000..28832c7f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/for-of-lhs/output.json @@ -0,0 +1,207 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ForOfStatement", + "await": false, + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "right": { + "kind": "ArrayExpression", + "elements": [], + "trailingComma": false, + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "body": { + "kind": "EmptyStatement", + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + { + "kind": "ForOfStatement", + "await": false, + "left": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 2, + "col": 10, + "index": 29 + }, + "end": { + "row": 2, + "col": 11, + "index": 30 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 2, + "col": 7, + "index": 26 + }, + "end": { + "row": 2, + "col": 8, + "index": 27 + } + }, + "start": { + "row": 2, + "col": 7, + "index": 26 + }, + "end": { + "row": 2, + "col": 8, + "index": 27 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 25 + }, + "end": { + "row": 2, + "col": 11, + "index": 30 + } + }, + "right": { + "kind": "ArrayExpression", + "elements": [], + "trailingComma": false, + "start": { + "row": 2, + "col": 15, + "index": 34 + }, + "end": { + "row": 2, + "col": 17, + "index": 36 + } + }, + "body": { + "kind": "EmptyStatement", + "start": { + "row": 2, + "col": 18, + "index": 37 + }, + "end": { + "row": 2, + "col": 19, + "index": 38 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 20 + }, + "end": { + "row": 2, + "col": 19, + "index": 38 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 39 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/input.ts new file mode 100644 index 00000000..517b1675 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/input.ts @@ -0,0 +1,4 @@ +(a:b); +(a:b,c:d); +[a:b]; +[a:b, c:d]; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/output.txt new file mode 100644 index 00000000..0d756d13 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/invalid/output.txt @@ -0,0 +1 @@ +[Syntax Error]: Unexpect token :(3, 3). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/input.ts new file mode 100644 index 00000000..c35da37d --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/input.ts @@ -0,0 +1 @@ +(a as number as any) = 42; \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/output.json new file mode 100644 index 00000000..562c5a80 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/multiple-assert-and-assign/output.json @@ -0,0 +1,123 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + }, + "parentheses": true + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "42", + "start": { + "row": 1, + "col": 24, + "index": 23 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/input.ts new file mode 100644 index 00000000..1b43aa2f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/input.ts @@ -0,0 +1 @@ +((a as any) as string) = null diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/output.json new file mode 100644 index 00000000..74ba51f8 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/nested-parenthesized-assert-and-assign/output.json @@ -0,0 +1,123 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSAsExpression", + "expression": { + "kind": "TSAsExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 4, + "index": 3 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + }, + "parentheses": true + }, + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + }, + "parentheses": true + }, + "right": { + "kind": "NullLiteral", + "start": { + "row": 1, + "col": 26, + "index": 25 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + } + ], + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 2, + "col": 1, + "index": 30 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/input.ts new file mode 100644 index 00000000..29cb0c03 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/input.ts @@ -0,0 +1 @@ +x! / 2 diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/output.json new file mode 100644 index 00000000..62bc7b68 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-2/output.json @@ -0,0 +1,83 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "/", + "left": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "2", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 7 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/input.ts new file mode 100644 index 00000000..759fd689 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/input.ts @@ -0,0 +1 @@ +const x = foo()!; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/output.json new file mode 100644 index 00000000..e825a3be --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-3/output.json @@ -0,0 +1,101 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "x", + "optional": false, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "init": { + "kind": 10255, + "expression": { + "kind": "CallExpression", + "optional": false, + "callee": { + "kind": "Identifer", + "name": "foo", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "arguments": [], + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 16, + "index": 15 + } + }, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + }, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 18 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/input.ts new file mode 100644 index 00000000..ae793d50 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/input.ts @@ -0,0 +1 @@ +x! *= 1 diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/output.json new file mode 100644 index 00000000..4104b89f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign-2/output.json @@ -0,0 +1,83 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "*=", + "left": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 8 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/input.ts new file mode 100644 index 00000000..da07f8ef --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/input.ts @@ -0,0 +1 @@ +x! += 1; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/output.json new file mode 100644 index 00000000..c0468a5f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-assign/output.json @@ -0,0 +1,83 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "+=", + "left": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 9 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/input.ts new file mode 100644 index 00000000..d60cf58b --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/input.ts @@ -0,0 +1 @@ +x.v! < y.v!; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/output.json new file mode 100644 index 00000000..277f973d --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-and-relational/output.json @@ -0,0 +1,154 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "<", + "left": { + "kind": 10255, + "expression": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "property": { + "kind": "Identifer", + "name": "v", + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 4, + "index": 3 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 4, + "index": 3 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + }, + "right": { + "kind": 10255, + "expression": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "property": { + "kind": "Identifer", + "name": "v", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 13 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/input.ts new file mode 100644 index 00000000..0fce6886 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/input.ts @@ -0,0 +1,2 @@ +a +!b diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/output.json new file mode 100644 index 00000000..736567b8 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-false-positive/output.json @@ -0,0 +1,83 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "UnaryExpression", + "operator": "!", + "argument": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 2, + "col": 2, + "index": 3 + }, + "end": { + "row": 2, + "col": 3, + "index": 4 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 2 + }, + "end": { + "row": 2, + "col": 3, + "index": 4 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 2 + }, + "end": { + "row": 2, + "col": 3, + "index": 4 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 5 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/input.ts new file mode 100644 index 00000000..eeeabeef --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/input.ts @@ -0,0 +1,6 @@ +(a!) => b; +(a! = b) => c; +([a!]) => c; +({a: a!}) => c; +([...a!]) => c; +({...a!}) => c; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/output.txt new file mode 100644 index 00000000..be22d978 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-invalid-arrow-param/output.txt @@ -0,0 +1 @@ +[Syntax Error]: invalid assignment left-hand side (1, 9) \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/input.ts new file mode 100644 index 00000000..b89be6ad --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/input.ts @@ -0,0 +1 @@ +x!.y; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/output.json new file mode 100644 index 00000000..5166524f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion-then-property-access/output.json @@ -0,0 +1,84 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "property": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 1, + "col": 4, + "index": 3 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 6 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/input.ts new file mode 100644 index 00000000..703cb104 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/input.ts @@ -0,0 +1 @@ +x!; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/output.json new file mode 100644 index 00000000..0dd8496a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/null-assertion/output.json @@ -0,0 +1,55 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": 10255, + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 3, + "index": 2 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 4 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/input.ts new file mode 100644 index 00000000..b3198b63 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/input.ts @@ -0,0 +1,4 @@ +x satisfies T; +x < y satisfies boolean; // (x < y) satisfies boolean; +(a satisfies any) = null; +[(a satisfies any)] = b; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/output.json new file mode 100644 index 00000000..4d829357 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/satisfies/output.json @@ -0,0 +1,341 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSSatisfiesExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSSatisfiesExpression", + "expression": { + "kind": "BinaryExpression", + "operator": "<", + "left": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 1, + "index": 15 + }, + "end": { + "row": 2, + "col": 2, + "index": 16 + } + }, + "right": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 2, + "col": 5, + "index": 19 + }, + "end": { + "row": 2, + "col": 6, + "index": 20 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 15 + }, + "end": { + "row": 2, + "col": 6, + "index": 20 + } + }, + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 2, + "col": 17, + "index": 31 + }, + "end": { + "row": 2, + "col": 24, + "index": 38 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 15 + }, + "end": { + "row": 2, + "col": 24, + "index": 38 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 15 + }, + "end": { + "row": 2, + "col": 24, + "index": 38 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSSatisfiesExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 3, + "col": 2, + "index": 71 + }, + "end": { + "row": 3, + "col": 3, + "index": 72 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 3, + "col": 14, + "index": 83 + }, + "end": { + "row": 3, + "col": 17, + "index": 86 + } + }, + "start": { + "row": 3, + "col": 2, + "index": 71 + }, + "end": { + "row": 3, + "col": 17, + "index": 86 + }, + "parentheses": true + }, + "right": { + "kind": "NullLiteral", + "start": { + "row": 3, + "col": 21, + "index": 90 + }, + "end": { + "row": 3, + "col": 25, + "index": 94 + } + }, + "start": { + "row": 3, + "col": 2, + "index": 71 + }, + "end": { + "row": 3, + "col": 25, + "index": 94 + } + }, + "start": { + "row": 3, + "col": 2, + "index": 71 + }, + "end": { + "row": 3, + "col": 25, + "index": 94 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "ArrayPattern", + "elements": [ + { + "kind": "TSSatisfiesExpression", + "expression": { + "kind": "Identifer", + "name": "a", + "start": { + "row": 4, + "col": 3, + "index": 98 + }, + "end": { + "row": 4, + "col": 4, + "index": 99 + } + }, + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 4, + "col": 15, + "index": 110 + }, + "end": { + "row": 4, + "col": 18, + "index": 113 + } + }, + "start": { + "row": 4, + "col": 3, + "index": 98 + }, + "end": { + "row": 4, + "col": 18, + "index": 113 + }, + "parentheses": true + } + ], + "start": { + "row": 4, + "col": 1, + "index": 96 + }, + "end": { + "row": 4, + "col": 20, + "index": 115 + } + }, + "right": { + "kind": "Identifer", + "name": "b", + "start": { + "row": 4, + "col": 23, + "index": 118 + }, + "end": { + "row": 4, + "col": 24, + "index": 119 + } + }, + "start": { + "row": 4, + "col": 1, + "index": 96 + }, + "end": { + "row": 4, + "col": 24, + "index": 119 + } + }, + "start": { + "row": 4, + "col": 1, + "index": 96 + }, + "end": { + "row": 4, + "col": 24, + "index": 119 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 121 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/input.ts new file mode 100644 index 00000000..7286cf70 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/input.ts @@ -0,0 +1 @@ +1 + 1; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/output.json new file mode 100644 index 00000000..ac7d1ecf --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-after-operator/output.json @@ -0,0 +1,96 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "+", + "left": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "right": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 14, + "index": 13 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 16 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/input.ts new file mode 100644 index 00000000..25af2257 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/input.ts @@ -0,0 +1 @@ +( x) += 1; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/output.json new file mode 100644 index 00000000..9d429dfe --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-and-assign/output.json @@ -0,0 +1,97 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "+=", + "left": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + }, + "parentheses": true + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 2, + "col": 1, + "index": 19 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/input.ts new file mode 100644 index 00000000..03f7f080 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/input.ts @@ -0,0 +1 @@ + 1 + 1; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/output.json new file mode 100644 index 00000000..09950aa3 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion-before-operator/output.json @@ -0,0 +1,96 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "+", + "left": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "right": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 14, + "index": 13 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 16 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/input.ts new file mode 100644 index 00000000..742b94ba --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/input.ts @@ -0,0 +1 @@ + 1; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/output.json new file mode 100644 index 00000000..7aa58bb9 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/type-assertion/output.json @@ -0,0 +1,68 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "DecimalLiteral", + "rawValue": "1", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 12 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/CHANGE.md b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/CHANGE.md new file mode 100644 index 00000000..72c9bb38 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/CHANGE.md @@ -0,0 +1,3 @@ +## Reason + +babel and TS playground is failed, but oxc and swc is pass, set to pass now. diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/input.ts new file mode 100644 index 00000000..065e483e --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/input.ts @@ -0,0 +1 @@ +foo = '100'; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/output.json new file mode 100644 index 00000000..6cb228a7 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-assert-and-assign/output.json @@ -0,0 +1,96 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "foo", + "start": { + "row": 1, + "col": 9, + "index": 8 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "right": { + "kind": "StringLiteral", + "value": "100", + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 21 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/CHANGE.md b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/CHANGE.md new file mode 100644 index 00000000..72c9bb38 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/CHANGE.md @@ -0,0 +1,3 @@ +## Reason + +babel and TS playground is failed, but oxc and swc is pass, set to pass now. diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/input.ts new file mode 100644 index 00000000..065e483e --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/input.ts @@ -0,0 +1 @@ +foo = '100'; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/output.json b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/output.json new file mode 100644 index 00000000..6cb228a7 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/cast/unparenthesized-type-assertion-and-assign/output.json @@ -0,0 +1,96 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "AssigmentExpression", + "operator": "=", + "left": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "foo", + "start": { + "row": 1, + "col": 9, + "index": 8 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "right": { + "kind": "StringLiteral", + "value": "100", + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 21 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/export/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/expect.json new file mode 100644 index 00000000..8aebefab --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/expect.json @@ -0,0 +1,7 @@ +{ + "expect": "Pass", + "config": { + "sourceType": "module", + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/export/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/input.ts new file mode 100644 index 00000000..5bda4c84 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/input.ts @@ -0,0 +1 @@ +export enum E {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/export/output.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/output.json new file mode 100644 index 00000000..f53bf0f9 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/export/output.json @@ -0,0 +1,71 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExportNamedDeclaration", + "specifiers": [], + "declaration": { + "kind": "TSEnumDeclaration", + "id": { + "kind": "Identifer", + "name": "E", + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "body": { + "kind": "TSEnumBody", + "members": [], + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + }, + "source": null, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 17 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/input.ts new file mode 100644 index 00000000..06c4ab79 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/input.ts @@ -0,0 +1,4 @@ +enum E { + const, + default +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/output.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/output.json new file mode 100644 index 00000000..cdcf5b12 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-reserved-words/output.json @@ -0,0 +1,113 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSEnumDeclaration", + "id": { + "kind": "Identifer", + "name": "E", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "body": { + "kind": "TSEnumBody", + "members": [ + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "const", + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 10, + "index": 18 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 10, + "index": 18 + } + }, + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "default", + "start": { + "row": 3, + "col": 5, + "index": 24 + }, + "end": { + "row": 3, + "col": 12, + "index": 31 + } + }, + "start": { + "row": 3, + "col": 5, + "index": 24 + }, + "end": { + "row": 3, + "col": 12, + "index": 31 + } + } + ], + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 4, + "col": 2, + "index": 33 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 2, + "index": 33 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 34 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/input.ts new file mode 100644 index 00000000..0c1f115f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/input.ts @@ -0,0 +1,3 @@ +enum E { + A = 0, +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/output.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/output.json new file mode 100644 index 00000000..1809ec93 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma-with-initializer/output.json @@ -0,0 +1,99 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSEnumDeclaration", + "id": { + "kind": "Identifer", + "name": "E", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "body": { + "kind": "TSEnumBody", + "members": [ + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "A", + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 6, + "index": 14 + } + }, + "init": { + "kind": "DecimalLiteral", + "rawValue": "0", + "start": { + "row": 2, + "col": 9, + "index": 17 + }, + "end": { + "row": 2, + "col": 10, + "index": 18 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 10, + "index": 18 + } + } + ], + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 3, + "col": 2, + "index": 21 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 21 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 22 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/input.ts new file mode 100644 index 00000000..7db24478 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/input.ts @@ -0,0 +1,3 @@ +enum E { + A, +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/output.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/output.json new file mode 100644 index 00000000..ac4499d6 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members-trailing-comma/output.json @@ -0,0 +1,85 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSEnumDeclaration", + "id": { + "kind": "Identifer", + "name": "E", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "body": { + "kind": "TSEnumBody", + "members": [ + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "A", + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 6, + "index": 14 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 6, + "index": 14 + } + } + ], + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 3, + "col": 2, + "index": 17 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 17 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 18 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/input.ts new file mode 100644 index 00000000..c0d9e76d --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/input.ts @@ -0,0 +1,4 @@ +enum E { + A, + B = 0 +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/enum/members/output.json b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/output.json new file mode 100644 index 00000000..1c2c6892 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/enum/members/output.json @@ -0,0 +1,127 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSEnumDeclaration", + "id": { + "kind": "Identifer", + "name": "E", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "body": { + "kind": "TSEnumBody", + "members": [ + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "A", + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 6, + "index": 14 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 13 + }, + "end": { + "row": 2, + "col": 6, + "index": 14 + } + }, + { + "kind": "TSEnumMember", + "computed": false, + "id": { + "kind": "Identifer", + "name": "B", + "start": { + "row": 3, + "col": 5, + "index": 20 + }, + "end": { + "row": 3, + "col": 6, + "index": 21 + } + }, + "init": { + "kind": "DecimalLiteral", + "rawValue": "0", + "start": { + "row": 3, + "col": 9, + "index": 24 + }, + "end": { + "row": 3, + "col": 10, + "index": 25 + } + }, + "start": { + "row": 3, + "col": 5, + "index": 20 + }, + "end": { + "row": 3, + "col": 10, + "index": 25 + } + } + ], + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 4, + "col": 2, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 2, + "index": 27 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 28 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/input.ts new file mode 100644 index 00000000..139772fa --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/input.ts @@ -0,0 +1 @@ +function f(x?: T): T {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/output.json new file mode 100644 index 00000000..f1d12c12 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/annotated/output.json @@ -0,0 +1,197 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "optional": true, + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 1, + "col": 16, + "index": 15 + } + } + ], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + }, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + } + ], + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 27 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/input.ts new file mode 100644 index 00000000..f696b003 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/input.ts @@ -0,0 +1,4 @@ +const fn = function* (input: T): Generator { + yield 2; + } + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/output.json new file mode 100644 index 00000000..570d9bfe --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous-generator/output.json @@ -0,0 +1,298 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "fn", + "optional": false, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "init": { + "kind": "FunctionExpression", + "name": null, + "generator": true, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "YieldExpression", + "argument": { + "kind": "DecimalLiteral", + "rawValue": "2", + "start": { + "row": 2, + "col": 11, + "index": 66 + }, + "end": { + "row": 2, + "col": 12, + "index": 67 + } + }, + "delegate": false, + "start": { + "row": 2, + "col": 5, + "index": 60 + }, + "end": { + "row": 2, + "col": 12, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 60 + }, + "end": { + "row": 2, + "col": 12, + "index": 67 + } + } + ], + "start": { + "row": 1, + "col": 55, + "index": 54 + }, + "end": { + "row": 3, + "col": 4, + "index": 72 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "input", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 34, + "index": 33 + } + }, + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 34, + "index": 33 + } + }, + "start": { + "row": 1, + "col": 31, + "index": 30 + }, + "end": { + "row": 1, + "col": 34, + "index": 33 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 26, + "index": 25 + }, + "end": { + "row": 1, + "col": 31, + "index": 30 + } + } + ], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + } + ], + "start": { + "row": 1, + "col": 22, + "index": 21 + }, + "end": { + "row": 1, + "col": 25, + "index": 24 + } + }, + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "Generator", + "start": { + "row": 1, + "col": 37, + "index": 36 + }, + "end": { + "row": 1, + "col": 46, + "index": 45 + } + }, + "typeArguments": { + "kind": "TSTypeParameterInstantiation", + "params": [ + { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 47, + "index": 46 + }, + "end": { + "row": 1, + "col": 53, + "index": 52 + } + } + ], + "start": { + "row": 1, + "col": 46, + "index": 45 + }, + "end": { + "row": 1, + "col": 54, + "index": 53 + } + }, + "start": { + "row": 1, + "col": 37, + "index": 36 + }, + "end": { + "row": 1, + "col": 46, + "index": 45 + } + }, + "start": { + "row": 1, + "col": 35, + "index": 34 + }, + "end": { + "row": 1, + "col": 46, + "index": 45 + } + }, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 3, + "col": 4, + "index": 72 + } + }, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 3, + "col": 4, + "index": 72 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 4, + "index": 72 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 3, + "index": 75 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/input.ts new file mode 100644 index 00000000..395ce03c --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/input.ts @@ -0,0 +1 @@ +const f = function(x?: T): T {}; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/output.json new file mode 100644 index 00000000..0f1a5ae9 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/anonymous/output.json @@ -0,0 +1,228 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "VariableDeclaration", + "variant": "const", + "declarations": [ + { + "kind": "VariableDeclarator", + "id": { + "kind": "Identifer", + "name": "f", + "optional": false, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + }, + "init": { + "kind": "FunctionExpression", + "name": null, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 27, + "index": 26 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 27, + "index": 26 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "optional": true, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + } + ], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + } + ], + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 31, + "index": 30 + }, + "end": { + "row": 1, + "col": 32, + "index": 31 + } + }, + "start": { + "row": 1, + "col": 31, + "index": 30 + }, + "end": { + "row": 1, + "col": 32, + "index": 31 + } + }, + "start": { + "row": 1, + "col": 29, + "index": 28 + }, + "end": { + "row": 1, + "col": 32, + "index": 31 + } + }, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + }, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 36 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/input.ts new file mode 100644 index 00000000..0988137a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/input.ts @@ -0,0 +1 @@ +function foo<>() {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/output.txt new file mode 100644 index 00000000..4bc88203 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/empty-type-parameters/output.txt @@ -0,0 +1 @@ +[Syntax Error]: Unexpect token >(1, 14). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/expect.json new file mode 100644 index 00000000..8aebefab --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/expect.json @@ -0,0 +1,7 @@ +{ + "expect": "Pass", + "config": { + "sourceType": "module", + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/input.ts new file mode 100644 index 00000000..37e894cd --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/input.ts @@ -0,0 +1 @@ +export default function(x?: number): void; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/output.json new file mode 100644 index 00000000..474321e9 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/export-default/output.json @@ -0,0 +1,113 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExportDefaultDeclaration", + "declaration": { + "kind": "TSDeclareFunction", + "name": null, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 29, + "index": 28 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + }, + "start": { + "row": 1, + "col": 27, + "index": 26 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + }, + "optional": true, + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 1, + "col": 38, + "index": 37 + }, + "end": { + "row": 1, + "col": 42, + "index": 41 + } + }, + "start": { + "row": 1, + "col": 36, + "index": 35 + }, + "end": { + "row": 1, + "col": 42, + "index": 41 + } + }, + "generator": false, + "async": false, + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 42, + "index": 41 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 42, + "index": 41 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 43 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/expect.json new file mode 100644 index 00000000..8aebefab --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/expect.json @@ -0,0 +1,7 @@ +{ + "expect": "Pass", + "config": { + "sourceType": "module", + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/input.ts new file mode 100644 index 00000000..2fb36ce1 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/input.ts @@ -0,0 +1,2 @@ +export function f(x: number): number; +export function f(x: string): string; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/output.json new file mode 100644 index 00000000..608b5e48 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/overloads/output.json @@ -0,0 +1,241 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExportNamedDeclaration", + "specifiers": [], + "declaration": { + "kind": "TSDeclareFunction", + "name": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 22, + "index": 21 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 31, + "index": 30 + }, + "end": { + "row": 1, + "col": 37, + "index": 36 + } + }, + "start": { + "row": 1, + "col": 29, + "index": 28 + }, + "end": { + "row": 1, + "col": 37, + "index": 36 + } + }, + "generator": false, + "async": false, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 37, + "index": 36 + } + }, + "source": null, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 37, + "index": 36 + } + }, + { + "kind": "ExportNamedDeclaration", + "specifiers": [], + "declaration": { + "kind": "TSDeclareFunction", + "name": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 2, + "col": 17, + "index": 54 + }, + "end": { + "row": 2, + "col": 18, + "index": 55 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 22, + "index": 59 + }, + "end": { + "row": 2, + "col": 28, + "index": 65 + } + }, + "start": { + "row": 2, + "col": 20, + "index": 57 + }, + "end": { + "row": 2, + "col": 28, + "index": 65 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 19, + "index": 56 + }, + "end": { + "row": 2, + "col": 20, + "index": 57 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 31, + "index": 68 + }, + "end": { + "row": 2, + "col": 37, + "index": 74 + } + }, + "start": { + "row": 2, + "col": 29, + "index": 66 + }, + "end": { + "row": 2, + "col": 37, + "index": 74 + } + }, + "generator": false, + "async": false, + "start": { + "row": 2, + "col": 8, + "index": 45 + }, + "end": { + "row": 2, + "col": 37, + "index": 74 + } + }, + "source": null, + "start": { + "row": 2, + "col": 1, + "index": 38 + }, + "end": { + "row": 2, + "col": 37, + "index": 74 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 76 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/input.ts new file mode 100644 index 00000000..374c7176 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/input.ts @@ -0,0 +1,2 @@ +function f(x: any): x is boolean {} +(function(x: any): x is boolean {}) diff --git a/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/output.json b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/output.json new file mode 100644 index 00000000..13c1e6ed --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/function/predicate-types/output.json @@ -0,0 +1,322 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "FunctionDeclaration", + "name": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 1, + "col": 34, + "index": 33 + }, + "end": { + "row": 1, + "col": 36, + "index": 35 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "asserts": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 1, + "col": 26, + "index": 25 + }, + "end": { + "row": 1, + "col": 33, + "index": 32 + } + }, + "start": { + "row": 1, + "col": 26, + "index": 25 + }, + "end": { + "row": 1, + "col": 33, + "index": 32 + } + }, + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 33, + "index": 32 + } + }, + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 33, + "index": 32 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 36, + "index": 35 + } + }, + { + "kind": "ExpressionStatement", + "expr": { + "kind": "FunctionExpression", + "name": null, + "generator": false, + "async": false, + "body": { + "kind": "FunctionBody", + "body": [], + "start": { + "row": 2, + "col": 33, + "index": 68 + }, + "end": { + "row": 2, + "col": 35, + "index": 70 + } + }, + "params": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 2, + "col": 14, + "index": 49 + }, + "end": { + "row": 2, + "col": 17, + "index": 52 + } + }, + "start": { + "row": 2, + "col": 12, + "index": 47 + }, + "end": { + "row": 2, + "col": 17, + "index": 52 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 11, + "index": 46 + }, + "end": { + "row": 2, + "col": 12, + "index": 47 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypePredicate", + "parameterName": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 20, + "index": 55 + }, + "end": { + "row": 2, + "col": 21, + "index": 56 + } + }, + "asserts": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSBooleanKeyword", + "start": { + "row": 2, + "col": 25, + "index": 60 + }, + "end": { + "row": 2, + "col": 32, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 25, + "index": 60 + }, + "end": { + "row": 2, + "col": 32, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 18, + "index": 53 + }, + "end": { + "row": 2, + "col": 32, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 18, + "index": 53 + }, + "end": { + "row": 2, + "col": 32, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 2, + "index": 37 + }, + "end": { + "row": 2, + "col": 35, + "index": 70 + }, + "parentheses": true + }, + "start": { + "row": 2, + "col": 2, + "index": 37 + }, + "end": { + "row": 2, + "col": 35, + "index": 70 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 72 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/input.ts new file mode 100644 index 00000000..5d6b5417 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/input.ts @@ -0,0 +1,3 @@ +interface I { + (x: number): void; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/output.json new file mode 100644 index 00000000..2b605638 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/call-signature/output.json @@ -0,0 +1,140 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSCallSignatureDeclaration", + "parameters": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 9, + "index": 22 + }, + "end": { + "row": 2, + "col": 15, + "index": 28 + } + }, + "start": { + "row": 2, + "col": 7, + "index": 20 + }, + "end": { + "row": 2, + "col": 15, + "index": 28 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 7, + "index": 20 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 18, + "index": 31 + }, + "end": { + "row": 2, + "col": 22, + "index": 35 + } + }, + "start": { + "row": 2, + "col": 16, + "index": 29 + }, + "end": { + "row": 2, + "col": 22, + "index": 35 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 22, + "index": 35 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 3, + "col": 2, + "index": 38 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 38 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 39 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/input.ts new file mode 100644 index 00000000..d726e4c4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/input.ts @@ -0,0 +1,3 @@ +interface I { + new (x: number): void; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/output.json new file mode 100644 index 00000000..6a7e8041 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/construct-signature/output.json @@ -0,0 +1,140 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSConstructSignatureDeclaration", + "parameters": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 13, + "index": 26 + }, + "end": { + "row": 2, + "col": 19, + "index": 32 + } + }, + "start": { + "row": 2, + "col": 11, + "index": 24 + }, + "end": { + "row": 2, + "col": 19, + "index": 32 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 10, + "index": 23 + }, + "end": { + "row": 2, + "col": 11, + "index": 24 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 22, + "index": 35 + }, + "end": { + "row": 2, + "col": 26, + "index": 39 + } + }, + "start": { + "row": 2, + "col": 20, + "index": 33 + }, + "end": { + "row": 2, + "col": 26, + "index": 39 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 26, + "index": 39 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 3, + "col": 2, + "index": 42 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 42 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 43 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/input.ts new file mode 100644 index 00000000..b0f7156d --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/input.ts @@ -0,0 +1 @@ +export default interface {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/output.txt new file mode 100644 index 00000000..a67ab555 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export-default/output.txt @@ -0,0 +1,6 @@ +[SyntaxError]: 'import' and 'export' may appear only with 'sourceType: "module"' (1,1) +1|export default interface {} + |^ +[SyntaxError]: Missing semicolon or line terminator. (1,26) +1|export default interface {} + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/expect.json new file mode 100644 index 00000000..8aebefab --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/expect.json @@ -0,0 +1,7 @@ +{ + "expect": "Pass", + "config": { + "sourceType": "module", + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/input.ts new file mode 100644 index 00000000..7049da87 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/input.ts @@ -0,0 +1,2 @@ +export interface I {} +export default interface A {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/export/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/output.json new file mode 100644 index 00000000..40656ed4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/export/output.json @@ -0,0 +1,127 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExportNamedDeclaration", + "specifiers": [], + "declaration": { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 19, + "index": 18 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [], + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "source": null, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + { + "kind": "ExportDefaultDeclaration", + "declaration": { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "A", + "start": { + "row": 2, + "col": 26, + "index": 47 + }, + "end": { + "row": 2, + "col": 27, + "index": 48 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [], + "start": { + "row": 2, + "col": 28, + "index": 49 + }, + "end": { + "row": 2, + "col": 30, + "index": 51 + } + }, + "start": { + "row": 2, + "col": 16, + "index": 37 + }, + "end": { + "row": 2, + "col": 30, + "index": 51 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 22 + }, + "end": { + "row": 2, + "col": 30, + "index": 51 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 1, + "index": 52 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/input.ts new file mode 100644 index 00000000..8cf474f2 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/input.ts @@ -0,0 +1 @@ +interface I extends X.Y {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/output.json new file mode 100644 index 00000000..1597d9f2 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/extends/output.json @@ -0,0 +1,154 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [ + { + "kind": "TSInterfaceHeritage", + "typeName": { + "kind": "TSQualifiedName", + "left": { + "kind": "Identifer", + "name": "X", + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 22, + "index": 21 + } + }, + "right": { + "kind": "Identifer", + "name": "Y", + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "typeArguments": { + "kind": "TSTypeParameterInstantiation", + "params": [ + { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "Z", + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + }, + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 26, + "index": 25 + } + } + ], + "start": { + "row": 1, + "col": 24, + "index": 23 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + } + ], + "body": { + "kind": "TSInterfaceBody", + "body": [], + "start": { + "row": 1, + "col": 28, + "index": 27 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 30 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/input.ts new file mode 100644 index 00000000..f4160e2f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/input.ts @@ -0,0 +1,4 @@ +interface Foo { + (a: string): string; + } + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/output.json new file mode 100644 index 00000000..2f86b796 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-1/output.json @@ -0,0 +1,182 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Foo", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSCallSignatureDeclaration", + "parameters": [ + { + "kind": "Identifer", + "name": "a", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 12, + "index": 27 + }, + "end": { + "row": 2, + "col": 18, + "index": 33 + } + }, + "start": { + "row": 2, + "col": 10, + "index": 25 + }, + "end": { + "row": 2, + "col": 18, + "index": 33 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 9, + "index": 24 + }, + "end": { + "row": 2, + "col": 10, + "index": 25 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 21, + "index": 36 + }, + "end": { + "row": 2, + "col": 27, + "index": 42 + } + }, + "start": { + "row": 2, + "col": 19, + "index": 34 + }, + "end": { + "row": 2, + "col": 27, + "index": 42 + } + }, + "typeParameters": { + "kind": 10257, + "params": [ + { + "kind": 10258, + "name": { + "kind": 10130, + "name": "T", + "start": { + "row": 2, + "col": 6, + "index": 21 + }, + "end": { + "row": 2, + "col": 7, + "index": 22 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 21 + }, + "end": { + "row": 2, + "col": 7, + "index": 22 + } + } + ], + "start": { + "row": 2, + "col": 5, + "index": 20 + }, + "end": { + "row": 2, + "col": 8, + "index": 23 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 20 + }, + "end": { + "row": 2, + "col": 27, + "index": 42 + } + } + ], + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 3, + "col": 4, + "index": 47 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 4, + "index": 47 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 3, + "index": 50 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/input.ts new file mode 100644 index 00000000..8c9e7dbb --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/input.ts @@ -0,0 +1 @@ +type Foo = () => number; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/output.json new file mode 100644 index 00000000..63533f6c --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-2/output.json @@ -0,0 +1,124 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSTypeAliasDeclaration", + "name": { + "kind": 10130, + "name": "Foo", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "typeAnnotation": { + "kind": "TSFunctionType", + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 21, + "index": 20 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "parameters": [], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + } + ], + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 28 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/input.ts new file mode 100644 index 00000000..ffc5771b --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/input.ts @@ -0,0 +1 @@ +type Foo = new () => void; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/output.json new file mode 100644 index 00000000..fb8c2a71 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-3/output.json @@ -0,0 +1,124 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSTypeAliasDeclaration", + "name": { + "kind": 10130, + "name": "Foo", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "typeAnnotation": { + "kind": "TSConstructorType", + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 1, + "col": 25, + "index": 24 + }, + "end": { + "row": 1, + "col": 29, + "index": 28 + } + }, + "start": { + "row": 1, + "col": 22, + "index": 21 + }, + "end": { + "row": 1, + "col": 29, + "index": 28 + } + }, + "parameters": [], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + }, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 18, + "index": 17 + } + } + ], + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 19, + "index": 18 + } + }, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 29, + "index": 28 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 30 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/input.ts new file mode 100644 index 00000000..fdaa4c13 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/input.ts @@ -0,0 +1,4 @@ +interface Foo { + new(a: string): string; + } + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/output.json new file mode 100644 index 00000000..de118c33 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-4/output.json @@ -0,0 +1,182 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Foo", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSConstructSignatureDeclaration", + "parameters": [ + { + "kind": "Identifer", + "name": "a", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 15, + "index": 30 + }, + "end": { + "row": 2, + "col": 21, + "index": 36 + } + }, + "start": { + "row": 2, + "col": 13, + "index": 28 + }, + "end": { + "row": 2, + "col": 21, + "index": 36 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 12, + "index": 27 + }, + "end": { + "row": 2, + "col": 13, + "index": 28 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 2, + "col": 24, + "index": 39 + }, + "end": { + "row": 2, + "col": 30, + "index": 45 + } + }, + "start": { + "row": 2, + "col": 22, + "index": 37 + }, + "end": { + "row": 2, + "col": 30, + "index": 45 + } + }, + "typeParameters": { + "kind": 10257, + "params": [ + { + "kind": 10258, + "name": { + "kind": 10130, + "name": "T", + "start": { + "row": 2, + "col": 9, + "index": 24 + }, + "end": { + "row": 2, + "col": 10, + "index": 25 + } + }, + "start": { + "row": 2, + "col": 9, + "index": 24 + }, + "end": { + "row": 2, + "col": 10, + "index": 25 + } + } + ], + "start": { + "row": 2, + "col": 8, + "index": 23 + }, + "end": { + "row": 2, + "col": 11, + "index": 26 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 20 + }, + "end": { + "row": 2, + "col": 30, + "index": 45 + } + } + ], + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 3, + "col": 4, + "index": 50 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 4, + "index": 50 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 3, + "index": 53 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/input.ts new file mode 100644 index 00000000..2c2ed109 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/input.ts @@ -0,0 +1,4 @@ +interface Foo { + foo(x: number): void; + } + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/output.json new file mode 100644 index 00000000..24655388 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/function-like-node-5/output.json @@ -0,0 +1,198 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Foo", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "foo", + "start": { + "row": 2, + "col": 5, + "index": 20 + }, + "end": { + "row": 2, + "col": 8, + "index": 23 + } + }, + "computed": false, + "optional": false, + "parameters": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 15, + "index": 30 + }, + "end": { + "row": 2, + "col": 21, + "index": 36 + } + }, + "start": { + "row": 2, + "col": 13, + "index": 28 + }, + "end": { + "row": 2, + "col": 21, + "index": 36 + } + }, + "optional": false, + "start": { + "row": 2, + "col": 12, + "index": 27 + }, + "end": { + "row": 2, + "col": 13, + "index": 28 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 24, + "index": 39 + }, + "end": { + "row": 2, + "col": 28, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 22, + "index": 37 + }, + "end": { + "row": 2, + "col": 28, + "index": 43 + } + }, + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 2, + "col": 9, + "index": 24 + }, + "end": { + "row": 2, + "col": 10, + "index": 25 + } + }, + "start": { + "row": 2, + "col": 9, + "index": 24 + }, + "end": { + "row": 2, + "col": 10, + "index": 25 + } + } + ], + "start": { + "row": 2, + "col": 8, + "index": 23 + }, + "end": { + "row": 2, + "col": 11, + "index": 26 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 20 + }, + "end": { + "row": 2, + "col": 28, + "index": 43 + } + } + ], + "start": { + "row": 1, + "col": 15, + "index": 14 + }, + "end": { + "row": 3, + "col": 4, + "index": 48 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 4, + "index": 48 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 3, + "index": 51 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/input.ts new file mode 100644 index 00000000..62f2ede3 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/input.ts @@ -0,0 +1 @@ +interface I {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/output.json new file mode 100644 index 00000000..a17cc8f5 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/generic/output.json @@ -0,0 +1,196 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "constraint": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "object", + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 29, + "index": 28 + } + }, + "start": { + "row": 1, + "col": 23, + "index": 22 + }, + "end": { + "row": 1, + "col": 29, + "index": 28 + } + }, + "default": { + "kind": "TSTypeLiteral", + "members": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 34, + "index": 33 + }, + "end": { + "row": 1, + "col": 35, + "index": 34 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 37, + "index": 36 + }, + "end": { + "row": 1, + "col": 43, + "index": 42 + } + }, + "start": { + "row": 1, + "col": 35, + "index": 34 + }, + "end": { + "row": 1, + "col": 43, + "index": 42 + } + }, + "start": { + "row": 1, + "col": 34, + "index": 33 + }, + "end": { + "row": 1, + "col": 43, + "index": 42 + } + } + ], + "start": { + "row": 1, + "col": 32, + "index": 31 + }, + "end": { + "row": 1, + "col": 45, + "index": 44 + } + }, + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 14, + "index": 13 + } + }, + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 45, + "index": 44 + } + } + ], + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 46, + "index": 45 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [], + "start": { + "row": 1, + "col": 47, + "index": 46 + }, + "end": { + "row": 1, + "col": 49, + "index": 48 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 49, + "index": 48 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 49 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/input.ts new file mode 100644 index 00000000..688dc322 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/input.ts @@ -0,0 +1,4 @@ +interface I { + [Symbol.iterator](): void; + [Symbol.iterator]?(): number; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/output.json new file mode 100644 index 00000000..70997e16 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-computed/output.json @@ -0,0 +1,228 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "Symbol", + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 12, + "index": 25 + } + }, + "property": { + "kind": "Identifer", + "name": "iterator", + "start": { + "row": 2, + "col": 13, + "index": 26 + }, + "end": { + "row": 2, + "col": 21, + "index": 34 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 21, + "index": 34 + } + }, + "computed": true, + "optional": false, + "parameters": [], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 26, + "index": 39 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 24, + "index": 37 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + { + "kind": "TSMethodSignature", + "key": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "Symbol", + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 12, + "index": 56 + } + }, + "property": { + "kind": "Identifer", + "name": "iterator", + "start": { + "row": 3, + "col": 13, + "index": 57 + }, + "end": { + "row": 3, + "col": 21, + "index": 65 + } + }, + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 21, + "index": 65 + } + }, + "computed": true, + "optional": true, + "parameters": [], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 3, + "col": 27, + "index": 71 + }, + "end": { + "row": 3, + "col": 33, + "index": 77 + } + }, + "start": { + "row": 3, + "col": 25, + "index": 69 + }, + "end": { + "row": 3, + "col": 33, + "index": 77 + } + }, + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 33, + "index": 77 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 4, + "col": 2, + "index": 80 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 2, + "index": 80 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 81 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/input.ts new file mode 100644 index 00000000..27f96200 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/input.ts @@ -0,0 +1,3 @@ +interface I { + m(): T; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/output.json new file mode 100644 index 00000000..6630293f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-generic/output.json @@ -0,0 +1,267 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "m", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 6, + "index": 19 + } + }, + "computed": false, + "optional": false, + "parameters": [], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 2, + "col": 44, + "index": 57 + }, + "end": { + "row": 2, + "col": 45, + "index": 58 + } + }, + "start": { + "row": 2, + "col": 44, + "index": 57 + }, + "end": { + "row": 2, + "col": 45, + "index": 58 + } + }, + "start": { + "row": 2, + "col": 42, + "index": 55 + }, + "end": { + "row": 2, + "col": 45, + "index": 58 + } + }, + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "constraint": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "object", + "start": { + "row": 2, + "col": 17, + "index": 30 + }, + "end": { + "row": 2, + "col": 23, + "index": 36 + } + }, + "start": { + "row": 2, + "col": 17, + "index": 30 + }, + "end": { + "row": 2, + "col": 23, + "index": 36 + } + }, + "default": { + "kind": "TSTypeLiteral", + "members": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 28, + "index": 41 + }, + "end": { + "row": 2, + "col": 29, + "index": 42 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 31, + "index": 44 + }, + "end": { + "row": 2, + "col": 37, + "index": 50 + } + }, + "start": { + "row": 2, + "col": 29, + "index": 42 + }, + "end": { + "row": 2, + "col": 37, + "index": 50 + } + }, + "start": { + "row": 2, + "col": 28, + "index": 41 + }, + "end": { + "row": 2, + "col": 37, + "index": 50 + } + } + ], + "start": { + "row": 2, + "col": 26, + "index": 39 + }, + "end": { + "row": 2, + "col": 39, + "index": 52 + } + }, + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 2, + "col": 7, + "index": 20 + }, + "end": { + "row": 2, + "col": 8, + "index": 21 + } + }, + "start": { + "row": 2, + "col": 7, + "index": 20 + }, + "end": { + "row": 2, + "col": 39, + "index": 52 + } + } + ], + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 40, + "index": 53 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 45, + "index": 58 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 3, + "col": 2, + "index": 61 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 61 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 62 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/input.ts new file mode 100644 index 00000000..9ceae32a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/input.ts @@ -0,0 +1,3 @@ +interface I { + m?(): void; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/output.json new file mode 100644 index 00000000..9aa98f6c --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-optional/output.json @@ -0,0 +1,114 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "m", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 6, + "index": 19 + } + }, + "computed": false, + "optional": true, + "parameters": [], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 11, + "index": 24 + }, + "end": { + "row": 2, + "col": 15, + "index": 28 + } + }, + "start": { + "row": 2, + "col": 9, + "index": 22 + }, + "end": { + "row": 2, + "col": 15, + "index": 28 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 15, + "index": 28 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 3, + "col": 2, + "index": 31 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 31 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 32 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/input.ts new file mode 100644 index 00000000..8d4d83dc --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/input.ts @@ -0,0 +1,4 @@ +interface I { + m(); + m(x?: number, ...y: number[]): void; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/output.json new file mode 100644 index 00000000..fe40cbef --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/method-plain/output.json @@ -0,0 +1,253 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "m", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 6, + "index": 19 + } + }, + "computed": false, + "optional": false, + "parameters": [], + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 8, + "index": 21 + } + }, + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "m", + "start": { + "row": 3, + "col": 5, + "index": 27 + }, + "end": { + "row": 3, + "col": 6, + "index": 28 + } + }, + "computed": false, + "optional": false, + "parameters": [ + { + "kind": "Identifer", + "name": "x", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 3, + "col": 11, + "index": 33 + }, + "end": { + "row": 3, + "col": 17, + "index": 39 + } + }, + "start": { + "row": 3, + "col": 9, + "index": 31 + }, + "end": { + "row": 3, + "col": 17, + "index": 39 + } + }, + "optional": true, + "start": { + "row": 3, + "col": 7, + "index": 29 + }, + "end": { + "row": 3, + "col": 8, + "index": 30 + } + }, + { + "kind": "RestElement", + "argument": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 3, + "col": 22, + "index": 44 + }, + "end": { + "row": 3, + "col": 23, + "index": 45 + } + }, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSArrayType", + "elementType": { + "kind": "TSNumberKeyword", + "start": { + "row": 3, + "col": 25, + "index": 47 + }, + "end": { + "row": 3, + "col": 31, + "index": 53 + } + }, + "start": { + "row": 3, + "col": 25, + "index": 47 + }, + "end": { + "row": 3, + "col": 33, + "index": 55 + } + }, + "start": { + "row": 3, + "col": 23, + "index": 45 + }, + "end": { + "row": 3, + "col": 33, + "index": 55 + } + }, + "optional": false, + "start": { + "row": 3, + "col": 19, + "index": 41 + }, + "end": { + "row": 3, + "col": 23, + "index": 45 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 3, + "col": 36, + "index": 58 + }, + "end": { + "row": 3, + "col": 40, + "index": 62 + } + }, + "start": { + "row": 3, + "col": 34, + "index": 56 + }, + "end": { + "row": 3, + "col": 40, + "index": 62 + } + }, + "start": { + "row": 3, + "col": 5, + "index": 27 + }, + "end": { + "row": 3, + "col": 40, + "index": 62 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 4, + "col": 2, + "index": 65 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 2, + "index": 65 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 66 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/input.ts new file mode 100644 index 00000000..707fdd6c --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/input.ts @@ -0,0 +1,2 @@ +interface +F {} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/output.txt new file mode 100644 index 00000000..84d13b90 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line-error/output.txt @@ -0,0 +1,3 @@ +[SyntaxError]: Missing semicolon or line terminator. (2,3) +2|F {} + | ^ diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/expect.json new file mode 100644 index 00000000..bfeea3c0 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/expect.json @@ -0,0 +1,7 @@ +{ + "expect": "Failed", + "config": { + "sourceType": "module", + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/input.ts new file mode 100644 index 00000000..2c77ad6a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/input.ts @@ -0,0 +1,3 @@ +interface +F +{} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/output.txt new file mode 100644 index 00000000..8e6f2642 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/new-line/output.txt @@ -0,0 +1,3 @@ +[SyntaxError]: unexpect keyword in strict mode (1,1) +1|interface + |^ diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/input.ts new file mode 100644 index 00000000..b886f007 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/input.ts @@ -0,0 +1,6 @@ +interface A { + foo([]?): void; + bar({}, []?): any; + baz(a: string, b: number, []?): void; + } + \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/output.json new file mode 100644 index 00000000..f826e51c --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/pattern-parameters/output.json @@ -0,0 +1,371 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "A", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "foo", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 8, + "index": 21 + } + }, + "computed": false, + "optional": false, + "parameters": [ + { + "kind": "ArrayPattern", + "elements": [], + "start": { + "row": 2, + "col": 9, + "index": 22 + }, + "optional": true, + "end": { + "row": 2, + "col": 11, + "index": 24 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 15, + "index": 28 + }, + "end": { + "row": 2, + "col": 19, + "index": 32 + } + }, + "start": { + "row": 2, + "col": 13, + "index": 26 + }, + "end": { + "row": 2, + "col": 19, + "index": 32 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 19, + "index": 32 + } + }, + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "bar", + "start": { + "row": 3, + "col": 5, + "index": 38 + }, + "end": { + "row": 3, + "col": 8, + "index": 41 + } + }, + "computed": false, + "optional": false, + "parameters": [ + { + "kind": "ObjectPattern", + "properties": [], + "optional": false, + "start": { + "row": 3, + "col": 9, + "index": 42 + }, + "end": { + "row": 3, + "col": 11, + "index": 44 + } + }, + { + "kind": "ArrayPattern", + "elements": [], + "start": { + "row": 3, + "col": 13, + "index": 46 + }, + "optional": true, + "end": { + "row": 3, + "col": 15, + "index": 48 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSAnyKeyword", + "start": { + "row": 3, + "col": 19, + "index": 52 + }, + "end": { + "row": 3, + "col": 22, + "index": 55 + } + }, + "start": { + "row": 3, + "col": 17, + "index": 50 + }, + "end": { + "row": 3, + "col": 22, + "index": 55 + } + }, + "start": { + "row": 3, + "col": 5, + "index": 38 + }, + "end": { + "row": 3, + "col": 22, + "index": 55 + } + }, + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "baz", + "start": { + "row": 4, + "col": 5, + "index": 61 + }, + "end": { + "row": 4, + "col": 8, + "index": 64 + } + }, + "computed": false, + "optional": false, + "parameters": [ + { + "kind": "Identifer", + "name": "a", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSStringKeyword", + "start": { + "row": 4, + "col": 12, + "index": 68 + }, + "end": { + "row": 4, + "col": 18, + "index": 74 + } + }, + "start": { + "row": 4, + "col": 10, + "index": 66 + }, + "end": { + "row": 4, + "col": 18, + "index": 74 + } + }, + "optional": false, + "start": { + "row": 4, + "col": 9, + "index": 65 + }, + "end": { + "row": 4, + "col": 10, + "index": 66 + } + }, + { + "kind": "Identifer", + "name": "b", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 4, + "col": 23, + "index": 79 + }, + "end": { + "row": 4, + "col": 29, + "index": 85 + } + }, + "start": { + "row": 4, + "col": 21, + "index": 77 + }, + "end": { + "row": 4, + "col": 29, + "index": 85 + } + }, + "optional": false, + "start": { + "row": 4, + "col": 20, + "index": 76 + }, + "end": { + "row": 4, + "col": 21, + "index": 77 + } + }, + { + "kind": "ArrayPattern", + "elements": [], + "start": { + "row": 4, + "col": 31, + "index": 87 + }, + "optional": true, + "end": { + "row": 4, + "col": 33, + "index": 89 + } + } + ], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 4, + "col": 37, + "index": 93 + }, + "end": { + "row": 4, + "col": 41, + "index": 97 + } + }, + "start": { + "row": 4, + "col": 35, + "index": 91 + }, + "end": { + "row": 4, + "col": 41, + "index": 97 + } + }, + "start": { + "row": 4, + "col": 5, + "index": 61 + }, + "end": { + "row": 4, + "col": 41, + "index": 97 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 5, + "col": 4, + "index": 102 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 4, + "index": 102 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 6, + "col": 3, + "index": 105 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/input.ts new file mode 100644 index 00000000..94c10ef4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/input.ts @@ -0,0 +1,5 @@ +interface I { + x; + y: number; + z?: number; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/output.json new file mode 100644 index 00000000..ab27ec54 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/properties/output.json @@ -0,0 +1,197 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 6, + "index": 19 + } + }, + "computed": false, + "optional": false, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 6, + "index": 19 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 3, + "col": 5, + "index": 25 + }, + "end": { + "row": 3, + "col": 6, + "index": 26 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 3, + "col": 8, + "index": 28 + }, + "end": { + "row": 3, + "col": 14, + "index": 34 + } + }, + "start": { + "row": 3, + "col": 6, + "index": 26 + }, + "end": { + "row": 3, + "col": 14, + "index": 34 + } + }, + "start": { + "row": 3, + "col": 5, + "index": 25 + }, + "end": { + "row": 3, + "col": 14, + "index": 34 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "z", + "start": { + "row": 4, + "col": 5, + "index": 40 + }, + "end": { + "row": 4, + "col": 6, + "index": 41 + } + }, + "computed": false, + "optional": true, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 4, + "col": 9, + "index": 44 + }, + "end": { + "row": 4, + "col": 15, + "index": 50 + } + }, + "start": { + "row": 4, + "col": 7, + "index": 42 + }, + "end": { + "row": 4, + "col": 15, + "index": 50 + } + }, + "start": { + "row": 4, + "col": 5, + "index": 40 + }, + "end": { + "row": 4, + "col": 15, + "index": 50 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 5, + "col": 2, + "index": 53 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 2, + "index": 53 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 6, + "col": 1, + "index": 54 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/input.ts new file mode 100644 index 00000000..78f3ac4a --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/input.ts @@ -0,0 +1,4 @@ +interface I { + [Symbol.iterator]: number; + [Symbol.iterator]?: number; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/output.json new file mode 100644 index 00000000..e01b2ed5 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-computed/output.json @@ -0,0 +1,226 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "Symbol", + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 12, + "index": 25 + } + }, + "property": { + "kind": "Identifer", + "name": "iterator", + "start": { + "row": 2, + "col": 13, + "index": 26 + }, + "end": { + "row": 2, + "col": 21, + "index": 34 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 21, + "index": 34 + } + }, + "computed": true, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 24, + "index": 37 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 22, + "index": 35 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + "start": { + "row": 2, + "col": 6, + "index": 19 + }, + "end": { + "row": 2, + "col": 30, + "index": 43 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "MemberExpression", + "computed": false, + "optional": false, + "object": { + "kind": "Identifer", + "name": "Symbol", + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 12, + "index": 56 + } + }, + "property": { + "kind": "Identifer", + "name": "iterator", + "start": { + "row": 3, + "col": 13, + "index": 57 + }, + "end": { + "row": 3, + "col": 21, + "index": 65 + } + }, + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 21, + "index": 65 + } + }, + "computed": true, + "optional": true, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 3, + "col": 25, + "index": 69 + }, + "end": { + "row": 3, + "col": 31, + "index": 75 + } + }, + "start": { + "row": 3, + "col": 23, + "index": 67 + }, + "end": { + "row": 3, + "col": 31, + "index": 75 + } + }, + "start": { + "row": 3, + "col": 6, + "index": 50 + }, + "end": { + "row": 3, + "col": 31, + "index": 75 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 4, + "col": 2, + "index": 78 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 2, + "index": 78 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 5, + "col": 1, + "index": 79 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/expect.json new file mode 100644 index 00000000..e5936a86 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Failed", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/input.ts new file mode 100644 index 00000000..2eb4e828 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/input.ts @@ -0,0 +1 @@ +interface I { x: number = 1;} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/output.txt b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/output.txt new file mode 100644 index 00000000..9992215b --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/property-initializer/output.txt @@ -0,0 +1 @@ +[Syntax Error]: Unexpect token =(1, 25). \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/input.ts new file mode 100644 index 00000000..76dff7a5 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/input.ts @@ -0,0 +1,3 @@ +interface I { + catch(): void; +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/output.json new file mode 100644 index 00000000..3b44da77 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/reserved-method-name/output.json @@ -0,0 +1,114 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "I", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSMethodSignature", + "key": { + "kind": "Identifer", + "name": "catch", + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 10, + "index": 23 + } + }, + "computed": false, + "optional": false, + "parameters": [], + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 2, + "col": 14, + "index": 27 + }, + "end": { + "row": 2, + "col": 18, + "index": 31 + } + }, + "start": { + "row": 2, + "col": 12, + "index": 25 + }, + "end": { + "row": 2, + "col": 18, + "index": 31 + } + }, + "start": { + "row": 2, + "col": 5, + "index": 18 + }, + "end": { + "row": 2, + "col": 18, + "index": 31 + } + } + ], + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 3, + "col": 2, + "index": 34 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 3, + "col": 2, + "index": 34 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 4, + "col": 1, + "index": 35 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/input.ts new file mode 100644 index 00000000..f8e941cd --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/input.ts @@ -0,0 +1,6 @@ +interface Comma { x: number, y: number } +interface Semi { x: number; y: number } +interface Newline { + x: number + y: number +} diff --git a/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/output.json b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/output.json new file mode 100644 index 00000000..6c43e921 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/interface/separators/output.json @@ -0,0 +1,474 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Comma", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 16, + "index": 15 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 22, + "index": 21 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 28, + "index": 27 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 1, + "col": 30, + "index": 29 + }, + "end": { + "row": 1, + "col": 31, + "index": 30 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 33, + "index": 32 + }, + "end": { + "row": 1, + "col": 39, + "index": 38 + } + }, + "start": { + "row": 1, + "col": 31, + "index": 30 + }, + "end": { + "row": 1, + "col": 39, + "index": 38 + } + }, + "start": { + "row": 1, + "col": 30, + "index": 29 + }, + "end": { + "row": 1, + "col": 39, + "index": 38 + } + } + ], + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 41, + "index": 40 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 41, + "index": 40 + } + }, + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Semi", + "start": { + "row": 2, + "col": 11, + "index": 51 + }, + "end": { + "row": 2, + "col": 15, + "index": 55 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 2, + "col": 18, + "index": 58 + }, + "end": { + "row": 2, + "col": 19, + "index": 59 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 21, + "index": 61 + }, + "end": { + "row": 2, + "col": 27, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 19, + "index": 59 + }, + "end": { + "row": 2, + "col": 27, + "index": 67 + } + }, + "start": { + "row": 2, + "col": 18, + "index": 58 + }, + "end": { + "row": 2, + "col": 27, + "index": 67 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 2, + "col": 29, + "index": 69 + }, + "end": { + "row": 2, + "col": 30, + "index": 70 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 2, + "col": 32, + "index": 72 + }, + "end": { + "row": 2, + "col": 38, + "index": 78 + } + }, + "start": { + "row": 2, + "col": 30, + "index": 70 + }, + "end": { + "row": 2, + "col": 38, + "index": 78 + } + }, + "start": { + "row": 2, + "col": 29, + "index": 69 + }, + "end": { + "row": 2, + "col": 38, + "index": 78 + } + } + ], + "start": { + "row": 2, + "col": 16, + "index": 56 + }, + "end": { + "row": 2, + "col": 40, + "index": 80 + } + }, + "start": { + "row": 2, + "col": 1, + "index": 41 + }, + "end": { + "row": 2, + "col": 40, + "index": 80 + } + }, + { + "kind": "TSInterfaceDeclaration", + "name": { + "kind": 10130, + "name": "Newline", + "start": { + "row": 3, + "col": 11, + "index": 91 + }, + "end": { + "row": 3, + "col": 18, + "index": 98 + } + }, + "extends": [], + "body": { + "kind": "TSInterfaceBody", + "body": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 4, + "col": 5, + "index": 105 + }, + "end": { + "row": 4, + "col": 6, + "index": 106 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 4, + "col": 8, + "index": 108 + }, + "end": { + "row": 4, + "col": 14, + "index": 114 + } + }, + "start": { + "row": 4, + "col": 6, + "index": 106 + }, + "end": { + "row": 4, + "col": 14, + "index": 114 + } + }, + "start": { + "row": 4, + "col": 5, + "index": 105 + }, + "end": { + "row": 4, + "col": 14, + "index": 114 + } + }, + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "y", + "start": { + "row": 5, + "col": 5, + "index": 119 + }, + "end": { + "row": 5, + "col": 6, + "index": 120 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 5, + "col": 8, + "index": 122 + }, + "end": { + "row": 5, + "col": 14, + "index": 128 + } + }, + "start": { + "row": 5, + "col": 6, + "index": 120 + }, + "end": { + "row": 5, + "col": 14, + "index": 128 + } + }, + "start": { + "row": 5, + "col": 5, + "index": 119 + }, + "end": { + "row": 5, + "col": 14, + "index": 128 + } + } + ], + "start": { + "row": 3, + "col": 19, + "index": 99 + }, + "end": { + "row": 6, + "col": 2, + "index": 130 + } + }, + "start": { + "row": 3, + "col": 1, + "index": 81 + }, + "end": { + "row": 6, + "col": 2, + "index": 130 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 7, + "col": 1, + "index": 131 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/input.ts new file mode 100644 index 00000000..9fb8928d --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/input.ts @@ -0,0 +1 @@ +type T = Array; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/output.json new file mode 100644 index 00000000..873fee5f --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic-complex-tokens-true/output.json @@ -0,0 +1,250 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSTypeAliasDeclaration", + "name": { + "kind": 10130, + "name": "T", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "Array", + "start": { + "row": 1, + "col": 44, + "index": 43 + }, + "end": { + "row": 1, + "col": 49, + "index": 48 + } + }, + "typeArguments": { + "kind": "TSTypeParameterInstantiation", + "params": [ + { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "U", + "start": { + "row": 1, + "col": 50, + "index": 49 + }, + "end": { + "row": 1, + "col": 51, + "index": 50 + } + }, + "start": { + "row": 1, + "col": 50, + "index": 49 + }, + "end": { + "row": 1, + "col": 51, + "index": 50 + } + } + ], + "start": { + "row": 1, + "col": 49, + "index": 48 + }, + "end": { + "row": 1, + "col": 52, + "index": 51 + } + }, + "start": { + "row": 1, + "col": 44, + "index": 43 + }, + "end": { + "row": 1, + "col": 49, + "index": 48 + } + }, + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "constraint": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "object", + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 18, + "index": 17 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "default": { + "kind": "TSTypeLiteral", + "members": [ + { + "kind": "TSPropertySignature", + "key": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 29, + "index": 28 + }, + "end": { + "row": 1, + "col": 30, + "index": 29 + } + }, + "computed": false, + "optional": false, + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 32, + "index": 31 + }, + "end": { + "row": 1, + "col": 38, + "index": 37 + } + }, + "start": { + "row": 1, + "col": 30, + "index": 29 + }, + "end": { + "row": 1, + "col": 38, + "index": 37 + } + }, + "start": { + "row": 1, + "col": 29, + "index": 28 + }, + "end": { + "row": 1, + "col": 38, + "index": 37 + } + } + ], + "start": { + "row": 1, + "col": 27, + "index": 26 + }, + "end": { + "row": 1, + "col": 40, + "index": 39 + } + }, + "name": { + "kind": "Identifer", + "name": "U", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 40, + "index": 39 + } + } + ], + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 41, + "index": 40 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 53, + "index": 52 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 53 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/input.ts new file mode 100644 index 00000000..48dcc5dd --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/input.ts @@ -0,0 +1 @@ +type T=U; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/output.json new file mode 100644 index 00000000..c8fe72fc --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/generic/output.json @@ -0,0 +1,111 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSTypeAliasDeclaration", + "name": { + "kind": 10130, + "name": "T", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "U", + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + }, + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "U", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + } + ], + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 10, + "index": 9 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 13, + "index": 12 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 13 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/input.ts new file mode 100644 index 00000000..42126b96 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/input.ts @@ -0,0 +1 @@ +type T = number; diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/output.json new file mode 100644 index 00000000..f7a41329 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-alias/plain/output.json @@ -0,0 +1,55 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "TSTypeAliasDeclaration", + "name": { + "kind": 10130, + "name": "T", + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 7, + "index": 6 + } + }, + "typeAnnotation": { + "kind": "TSNumberKeyword", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 16, + "index": 15 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 17, + "index": 16 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 17 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts new file mode 100644 index 00000000..22101bcf --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/input.ts @@ -0,0 +1 @@ +f<<(x) diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json new file mode 100644 index 00000000..d8333915 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/after-bit-shift/output.json @@ -0,0 +1,111 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": "<<", + "left": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "right": { + "kind": "TSTypeAssertionExpression", + "expression": { + "kind": "Identifer", + "name": "x", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + }, + "parentheses": true + }, + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "start": { + "row": 1, + "col": 4, + "index": 3 + }, + "end": { + "row": 1, + "col": 10, + "index": 9 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 10, + "index": 9 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 10, + "index": 9 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 10 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/input.ts new file mode 100644 index 00000000..94b8ba09 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/input.ts @@ -0,0 +1 @@ +f<(v: T) => void>(); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/output.json new file mode 100644 index 00000000..3a0cf7c9 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/call-expression/output.json @@ -0,0 +1,210 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "CallExpression", + "optional": false, + "callee": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "typeArguments": { + "kind": "TSTypeParameterInstantiation", + "params": [ + { + "kind": "TSFunctionType", + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 1, + "col": 16, + "index": 15 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 13, + "index": 12 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "parameters": [ + { + "kind": "Identifer", + "name": "v", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 11, + "index": 10 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 8, + "index": 7 + } + } + ], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 4, + "index": 3 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + }, + "start": { + "row": 1, + "col": 4, + "index": 3 + }, + "end": { + "row": 1, + "col": 5, + "index": 4 + } + } + ], + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "start": { + "row": 1, + "col": 3, + "index": 2 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "start": { + "row": 1, + "col": 2, + "index": 1 + }, + "end": { + "row": 1, + "col": 21, + "index": 20 + } + }, + "arguments": [], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 23, + "index": 22 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 23, + "index": 22 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 24 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/input.ts new file mode 100644 index 00000000..7991a4bb --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/input.ts @@ -0,0 +1 @@ +new f<(v: T) => void>(); diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/output.json new file mode 100644 index 00000000..14022fc4 --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/new-expression/output.json @@ -0,0 +1,209 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "NewExpression", + "callee": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "arguments": [], + "typeArguments": { + "kind": "TSTypeParameterInstantiation", + "params": [ + { + "kind": "TSFunctionType", + "returnType": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSVoidKeyword", + "start": { + "row": 1, + "col": 20, + "index": 19 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "start": { + "row": 1, + "col": 17, + "index": 16 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + }, + "parameters": [ + { + "kind": "Identifer", + "name": "v", + "typeAnnotation": { + "kind": "TSTypeAnnotation", + "typeAnnotation": { + "kind": "TSTypeReference", + "typeName": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 14, + "index": 13 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 14, + "index": 13 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 12, + "index": 11 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "optional": false, + "start": { + "row": 1, + "col": 11, + "index": 10 + }, + "end": { + "row": 1, + "col": 12, + "index": 11 + } + } + ], + "typeParameters": { + "kind": "TSTypeParameterDeclaration", + "params": [ + { + "kind": "TSTypeParameter", + "name": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + }, + "start": { + "row": 1, + "col": 8, + "index": 7 + }, + "end": { + "row": 1, + "col": 9, + "index": 8 + } + } + ], + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 10, + "index": 9 + } + }, + "start": { + "row": 1, + "col": 7, + "index": 6 + }, + "end": { + "row": 1, + "col": 24, + "index": 23 + } + } + ], + "start": { + "row": 1, + "col": 6, + "index": 5 + }, + "end": { + "row": 1, + "col": 25, + "index": 24 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 27, + "index": 26 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 28 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/expect.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/expect.json new file mode 100644 index 00000000..ef61e5ce --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/expect.json @@ -0,0 +1,6 @@ +{ + "expect": "Pass", + "config": { + "plugins": ["typescript"] + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts new file mode 100644 index 00000000..7e2a54ba --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/input.ts @@ -0,0 +1 @@ +f<< T > (()=>T) > T diff --git a/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json new file mode 100644 index 00000000..a3deafcc --- /dev/null +++ b/web-infras/parser/tests/fixtures/babel/typescript/type-arguments-bit-shift-left-like/type-arguments-like/output.json @@ -0,0 +1,143 @@ +{ + "kind": "Program", + "body": [ + { + "kind": "ExpressionStatement", + "expr": { + "kind": "BinaryExpression", + "operator": ">", + "left": { + "kind": "BinaryExpression", + "operator": ">", + "left": { + "kind": "BinaryExpression", + "operator": "<<", + "left": { + "kind": "Identifer", + "name": "f", + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 2, + "index": 1 + } + }, + "right": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 5, + "index": 4 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 6, + "index": 5 + } + }, + "right": { + "kind": "ArrowFunctionExpression", + "expressionBody": true, + "async": false, + "arguments": [], + "body": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 14, + "index": 13 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "start": { + "row": 1, + "col": 10, + "index": 9 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + }, + "parentheses": true + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 15, + "index": 14 + } + }, + "right": { + "kind": "Identifer", + "name": "T", + "start": { + "row": 1, + "col": 19, + "index": 18 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + }, + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 1, + "col": 20, + "index": 19 + } + } + ], + "start": { + "row": 1, + "col": 1, + "index": 0 + }, + "end": { + "row": 2, + "col": 1, + "index": 20 + } +} \ No newline at end of file diff --git a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-element/output.txt b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-element/output.txt index 022f7b98..d923ab07 100644 --- a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-element/output.txt +++ b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-element/output.txt @@ -1 +1,6 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: function statement requires a name (2,14) +2| function*(x = yield 3) {} + | ^ +[SyntaxError]: yield expression can not used in parameter list (2,19) +2| function*(x = yield 3) {} + | ^ diff --git a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-property/output.txt b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-property/output.txt index 022f7b98..94211de8 100644 --- a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-property/output.txt +++ b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-binding-property/output.txt @@ -1 +1,6 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: function statement requires a name (2,14) +2| function*({x: y = yield 3}) {} + | ^ +[SyntaxError]: yield expression can not used in parameter list (2,23) +2| function*({x: y = yield 3}) {} + | ^ diff --git a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-computed-property-name/output.txt b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-computed-property-name/output.txt index 022f7b98..6097e067 100644 --- a/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-computed-property-name/output.txt +++ b/web-infras/parser/tests/fixtures/esprima/ES6/generator/generator-parameter-invalid-computed-property-name/output.txt @@ -1 +1,6 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: function statement requires a name (2,14) +2| function*({[yield 3]: y}) {} + | ^ +[SyntaxError]: yield expression can not used in parameter list (2,17) +2| function*({[yield 3]: y}) {} + | ^ diff --git a/web-infras/parser/tests/fixtures/esprima/es2017/async/functions/invalid-export-async-function-expression/output.txt b/web-infras/parser/tests/fixtures/esprima/es2017/async/functions/invalid-export-async-function-expression/output.txt index 022f7b98..962042f3 100644 --- a/web-infras/parser/tests/fixtures/esprima/es2017/async/functions/invalid-export-async-function-expression/output.txt +++ b/web-infras/parser/tests/fixtures/esprima/es2017/async/functions/invalid-export-async-function-expression/output.txt @@ -1 +1,6 @@ -Cannot read properties of null (reading 'name') \ No newline at end of file +[SyntaxError]: 'import' and 'export' may appear only with 'sourceType: "module"' (1,1) +1|export async function() {} + |^ +[SyntaxError]: function statement requires a name (1,22) +1|export async function() {} + | ^ diff --git a/web-infras/parser/tests/parserRunner/helpers/transform.ts b/web-infras/parser/tests/parserRunner/helpers/transform.ts index d76b7239..a5e59c29 100644 --- a/web-infras/parser/tests/parserRunner/helpers/transform.ts +++ b/web-infras/parser/tests/parserRunner/helpers/transform.ts @@ -171,6 +171,14 @@ const VisitorTable: Visitor = { [SyntaxKinds.TSTypeParameter]: transformKind, [SyntaxKinds.TSVoidKeyword]: transformKind, [SyntaxKinds.TSInstantiationExpression]: transformKind, + [SyntaxKinds.TSInterfaceHeritage]: transformKind, + [SyntaxKinds.TSTypeAssertionExpression]: transformKind, + [SyntaxKinds.TSAsExpression]: transformKind, + [SyntaxKinds.TSSatisfiesExpression]: transformKind, + [SyntaxKinds.TSEnumDeclaration]: transformKind, + [SyntaxKinds.TSEnumBody]: transformKind, + [SyntaxKinds.TSEnumMember]: transformKind, + [SyntaxKinds.TSDeclareFunction]: transformKind, }; function transformKind(node: ModuleItem, visior: Visitor) { // @ts-expect-error a ast node's syntax kind must be table.