From 27f6ca2a7af9a621185e821cb3c3b5276d0a52cd Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 12 Mar 2024 14:24:59 -0400 Subject: [PATCH 1/3] Report grammar errors for invalid decorator grammar --- src/compiler/checker.ts | 75 +++++++++++++++++++ src/compiler/diagnosticMessages.json | 16 ++++ src/services/_namespaces/ts.codefix.ts | 1 + .../codefixes/wrapDecoratorInParentheses.ts | 35 +++++++++ .../decoratorOnClassMethod11.errors.txt | 6 +- .../reference/decoratorOnClassMethod11.js | 4 +- .../decoratorOnClassMethod11.symbols | 2 +- .../reference/decoratorOnClassMethod11.types | 3 +- .../decoratorOnClassMethod12.errors.txt | 6 +- .../reference/decoratorOnClassMethod12.js | 4 +- .../decoratorOnClassMethod12.symbols | 2 +- .../reference/decoratorOnClassMethod12.types | 3 +- .../reference/esDecorators-preservesThis.js | 4 +- .../esDecorators-preservesThis.symbols | 2 +- .../esDecorators-preservesThis.types | 3 +- .../class/method/decoratorOnClassMethod11.ts | 2 +- .../class/method/decoratorOnClassMethod12.ts | 2 +- .../esDecorators-preservesThis.ts | 2 +- .../codeFixWrapDecoratorInParentheses01.ts | 14 ++++ .../codeFixWrapDecoratorInParentheses_all.ts | 24 ++++++ 20 files changed, 189 insertions(+), 21 deletions(-) create mode 100644 src/services/codefixes/wrapDecoratorInParentheses.ts create mode 100644 tests/cases/fourslash/codeFixWrapDecoratorInParentheses01.ts create mode 100644 tests/cases/fourslash/codeFixWrapDecoratorInParentheses_all.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 820da4b78314a..7cc4ba6a2cfe5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -651,6 +651,7 @@ import { isNewExpression, isNodeDescendantOf, isNonNullAccess, + isNonNullExpression, isNullishCoalesce, isNumericLiteral, isNumericLiteralName, @@ -41576,8 +41577,82 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } + function checkGrammarDecorator(decorator: Decorator): boolean { + const sourceFile = getSourceFileOfNode(decorator); + if (!hasParseDiagnostics(sourceFile)) { + let node: Expression = decorator.expression; + + // DecoratorParenthesizedExpression : + // `(` Expression `)` + + if (isParenthesizedExpression(node)) { + return false; + } + + let canHaveCallExpression = true; + let errorNode: Node | undefined; + while (true) { + // Allow TS syntax such as non-null assertions and instantiation expressions + if (isExpressionWithTypeArguments(node) || isNonNullExpression(node)) { + node = node.expression; + continue; + } + + // DecoratorCallExpression : + // DecoratorMemberExpression Arguments + + if (isCallExpression(node)) { + if (!canHaveCallExpression) { + errorNode = node; + } + if (node.questionDotToken) { + // Even if we already have an error node, error at the `?.` token since it appears earlier. + errorNode = node.questionDotToken; + } + node = node.expression; + canHaveCallExpression = false; + continue; + } + + // DecoratorMemberExpression : + // IdentifierReference + // DecoratorMemberExpression `.` IdentifierName + // DecoratorMemberExpression `.` PrivateIdentifier + + if (isPropertyAccessExpression(node)) { + if (node.questionDotToken) { + // Even if we already have an error node, error at the `?.` token since it appears earlier. + errorNode = node.questionDotToken; + } + node = node.expression; + canHaveCallExpression = false; + continue; + } + + if (!isIdentifier(node)) { + // Even if we already have an error node, error at this node since it appears earlier. + errorNode = node; + } + + break; + } + + if (errorNode) { + addRelatedInfo( + error(decorator.expression, Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator), + createDiagnosticForNode(errorNode, Diagnostics.Invalid_syntax_in_decorator) + ); + return true; + } + } + + return false; + } + /** Check a decorator */ function checkDecorator(node: Decorator): void { + checkGrammarDecorator(node); + const signature = getResolvedSignature(node); checkDeprecatedSignature(signature, node); const returnType = getReturnTypeOfSignature(signature); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0bedb964ffdc4..33e8b022aede7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1637,6 +1637,14 @@ "category": "Error", "code": 1496 }, + "Expression must be enclosed in parentheses to be used as a decorator.": { + "category": "Error", + "code": 1497 + }, + "Invalid syntax in decorator.": { + "category": "Error", + "code": 1498 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", @@ -7776,6 +7784,14 @@ "category": "Message", "code": 95193 }, + "Wrap in parentheses": { + "category": "Message", + "code": 95194 + }, + "Wrap all invalid decorator expressions in parentheses": { + "category": "Message", + "code": 95195 + }, "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", diff --git a/src/services/_namespaces/ts.codefix.ts b/src/services/_namespaces/ts.codefix.ts index 72b1cb87c50f7..d04e1cbb5537a 100644 --- a/src/services/_namespaces/ts.codefix.ts +++ b/src/services/_namespaces/ts.codefix.ts @@ -64,6 +64,7 @@ export * from "../codefixes/useDefaultImport"; export * from "../codefixes/useBigintLiteral"; export * from "../codefixes/fixAddModuleReferTypeMissingTypeof"; export * from "../codefixes/wrapJsxInFragment"; +export * from "../codefixes/wrapDecoratorInParentheses"; export * from "../codefixes/convertToMappedObjectType"; export * from "../codefixes/removeAccidentalCallParentheses"; export * from "../codefixes/removeUnnecessaryAwait"; diff --git a/src/services/codefixes/wrapDecoratorInParentheses.ts b/src/services/codefixes/wrapDecoratorInParentheses.ts new file mode 100644 index 0000000000000..d940f696a799f --- /dev/null +++ b/src/services/codefixes/wrapDecoratorInParentheses.ts @@ -0,0 +1,35 @@ +import { + Debug, + Diagnostics, + factory, + findAncestor, + getTokenAtPosition, + isDecorator, + SourceFile, + textChanges +} from "../_namespaces/ts"; +import { + codeFixAll, + createCodeFixAction, + registerCodeFix, +} from "../_namespaces/ts.codefix"; + +const fixId = "wrapDecoratorInParentheses"; +const errorCodes = [Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator.code]; +registerCodeFix({ + errorCodes, + getCodeActions: function getCodeActionsToWrapDecoratorExpressionInParentheses(context) { + const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start)); + return [createCodeFixAction(fixId, changes, Diagnostics.Wrap_in_parentheses, fixId, Diagnostics.Wrap_all_invalid_decorator_expressions_in_parentheses)]; + }, + fixIds: [fixId], + getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start)), +}); + +function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) { + const token = getTokenAtPosition(sourceFile, pos); + const decorator = findAncestor(token, isDecorator)!; + Debug.assert(!!decorator, "Expected position to be owned by a decorator."); + const replacement = factory.createParenthesizedExpression(decorator.expression); + changeTracker.replaceNode(sourceFile, decorator.expression, replacement); +} diff --git a/tests/baselines/reference/decoratorOnClassMethod11.errors.txt b/tests/baselines/reference/decoratorOnClassMethod11.errors.txt index 2e2966549431f..fc5349bd32097 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod11.errors.txt @@ -1,4 +1,4 @@ -decoratorOnClassMethod11.ts(5,10): error TS2331: 'this' cannot be referenced in a module or namespace body. +decoratorOnClassMethod11.ts(5,11): error TS2331: 'this' cannot be referenced in a module or namespace body. ==== decoratorOnClassMethod11.ts (1 errors) ==== @@ -6,8 +6,8 @@ decoratorOnClassMethod11.ts(5,10): error TS2331: 'this' cannot be referenced in class C { decorator(target: Object, key: string): void { } - @this.decorator - ~~~~ + @(this.decorator) + ~~~~ !!! error TS2331: 'this' cannot be referenced in a module or namespace body. method() { } } diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index 7a151dbe4fab6..4d577dde5a628 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -5,7 +5,7 @@ module M { class C { decorator(target: Object, key: string): void { } - @this.decorator + @(this.decorator) method() { } } } @@ -25,7 +25,7 @@ var M; C.prototype.decorator = function (target, key) { }; C.prototype.method = function () { }; __decorate([ - this.decorator + (this.decorator) ], C.prototype, "method", null); return C; }()); diff --git a/tests/baselines/reference/decoratorOnClassMethod11.symbols b/tests/baselines/reference/decoratorOnClassMethod11.symbols index e324d00f499c2..2ab9662569ce9 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.symbols +++ b/tests/baselines/reference/decoratorOnClassMethod11.symbols @@ -13,7 +13,7 @@ module M { >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >key : Symbol(key, Decl(decoratorOnClassMethod11.ts, 2, 33)) - @this.decorator + @(this.decorator) method() { } >method : Symbol(C.method, Decl(decoratorOnClassMethod11.ts, 2, 56)) } diff --git a/tests/baselines/reference/decoratorOnClassMethod11.types b/tests/baselines/reference/decoratorOnClassMethod11.types index 1e2b117dc7f3b..f97d46d297a34 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.types +++ b/tests/baselines/reference/decoratorOnClassMethod11.types @@ -12,7 +12,8 @@ module M { >target : Object >key : string - @this.decorator + @(this.decorator) +>(this.decorator) : any >this.decorator : any >this : any >decorator : any diff --git a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt index 02ed35f402367..419533fd0cbb9 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt @@ -1,4 +1,4 @@ -decoratorOnClassMethod12.ts(6,10): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +decoratorOnClassMethod12.ts(6,11): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ==== decoratorOnClassMethod12.ts (1 errors) ==== @@ -7,8 +7,8 @@ decoratorOnClassMethod12.ts(6,10): error TS2660: 'super' can only be referenced decorator(target: Object, key: string): void { } } class C extends S { - @super.decorator - ~~~~~ + @(super.decorator) + ~~~~~ !!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. method() { } } diff --git a/tests/baselines/reference/decoratorOnClassMethod12.js b/tests/baselines/reference/decoratorOnClassMethod12.js index 46e44bf6cca61..831be5471530c 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.js +++ b/tests/baselines/reference/decoratorOnClassMethod12.js @@ -6,7 +6,7 @@ module M { decorator(target: Object, key: string): void { } } class C extends S { - @super.decorator + @(super.decorator) method() { } } } @@ -48,7 +48,7 @@ var M; } C.prototype.method = function () { }; __decorate([ - _super.decorator + (_super.decorator) ], C.prototype, "method", null); return C; }(S)); diff --git a/tests/baselines/reference/decoratorOnClassMethod12.symbols b/tests/baselines/reference/decoratorOnClassMethod12.symbols index 1d15b29121dec..838af744903cb 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.symbols +++ b/tests/baselines/reference/decoratorOnClassMethod12.symbols @@ -17,7 +17,7 @@ module M { >C : Symbol(C, Decl(decoratorOnClassMethod12.ts, 3, 5)) >S : Symbol(S, Decl(decoratorOnClassMethod12.ts, 0, 10)) - @super.decorator + @(super.decorator) method() { } >method : Symbol(C.method, Decl(decoratorOnClassMethod12.ts, 4, 23)) } diff --git a/tests/baselines/reference/decoratorOnClassMethod12.types b/tests/baselines/reference/decoratorOnClassMethod12.types index 72c6459f7ab6f..730423c6322e9 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.types +++ b/tests/baselines/reference/decoratorOnClassMethod12.types @@ -16,7 +16,8 @@ module M { >C : C >S : S - @super.decorator + @(super.decorator) +>(super.decorator) : any >super.decorator : any >super : any >decorator : any diff --git a/tests/baselines/reference/esDecorators-preservesThis.js b/tests/baselines/reference/esDecorators-preservesThis.js index 4a0b8a4ab2412..ceaac9e67721c 100644 --- a/tests/baselines/reference/esDecorators-preservesThis.js +++ b/tests/baselines/reference/esDecorators-preservesThis.js @@ -26,7 +26,7 @@ class C { class D extends DecoratorProvider { m() { class C { - @super.decorate + @(super.decorate) method1() { } @(super["decorate"]) @@ -114,7 +114,7 @@ class D extends DecoratorProvider { return class C { static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; - _method1_decorators = [super.decorate.bind(_outerThis)]; + _method1_decorators = [(super.decorate.bind(_outerThis))]; _method2_decorators = [(super["decorate"].bind(_outerThis))]; _method3_decorators = [((super.decorate.bind(_outerThis)))]; __esDecorate(this, null, _method1_decorators, { kind: "method", name: "method1", static: false, private: false, access: { has: obj => "method1" in obj, get: obj => obj.method1 }, metadata: _metadata }, null, _instanceExtraInitializers); diff --git a/tests/baselines/reference/esDecorators-preservesThis.symbols b/tests/baselines/reference/esDecorators-preservesThis.symbols index e4337caf5c8a6..7cafc37c2aa5a 100644 --- a/tests/baselines/reference/esDecorators-preservesThis.symbols +++ b/tests/baselines/reference/esDecorators-preservesThis.symbols @@ -62,7 +62,7 @@ class D extends DecoratorProvider { class C { >C : Symbol(C, Decl(esDecorators-preservesThis.ts, 23, 9)) - @super.decorate + @(super.decorate) >super.decorate : Symbol(DecoratorProvider.decorate, Decl(esDecorators-preservesThis.ts, 2, 33)) >super : Symbol(DecoratorProvider, Decl(esDecorators-preservesThis.ts, 0, 0)) >decorate : Symbol(DecoratorProvider.decorate, Decl(esDecorators-preservesThis.ts, 2, 33)) diff --git a/tests/baselines/reference/esDecorators-preservesThis.types b/tests/baselines/reference/esDecorators-preservesThis.types index 139812e62e7df..e5b814b8d81d9 100644 --- a/tests/baselines/reference/esDecorators-preservesThis.types +++ b/tests/baselines/reference/esDecorators-preservesThis.types @@ -60,7 +60,8 @@ class D extends DecoratorProvider { class C { >C : C - @super.decorate + @(super.decorate) +>(super.decorate) : (this: DecoratorProvider, v: T, ctx: DecoratorContext) => T >super.decorate : (this: DecoratorProvider, v: T, ctx: DecoratorContext) => T >super : DecoratorProvider >decorate : (this: DecoratorProvider, v: T, ctx: DecoratorContext) => T diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts index 058f8134880d4..26a01cb855b9c 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts @@ -4,7 +4,7 @@ module M { class C { decorator(target: Object, key: string): void { } - @this.decorator + @(this.decorator) method() { } } } \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts index 9af80e32c46b3..e353d0db587ee 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts @@ -5,7 +5,7 @@ module M { decorator(target: Object, key: string): void { } } class C extends S { - @super.decorator + @(super.decorator) method() { } } } \ No newline at end of file diff --git a/tests/cases/conformance/esDecorators/esDecorators-preservesThis.ts b/tests/cases/conformance/esDecorators/esDecorators-preservesThis.ts index 87e2a250d756f..a3583a656f405 100644 --- a/tests/cases/conformance/esDecorators/esDecorators-preservesThis.ts +++ b/tests/cases/conformance/esDecorators/esDecorators-preservesThis.ts @@ -24,7 +24,7 @@ class C { class D extends DecoratorProvider { m() { class C { - @super.decorate + @(super.decorate) method1() { } @(super["decorate"]) diff --git a/tests/cases/fourslash/codeFixWrapDecoratorInParentheses01.ts b/tests/cases/fourslash/codeFixWrapDecoratorInParentheses01.ts new file mode 100644 index 0000000000000..45a9756e5c150 --- /dev/null +++ b/tests/cases/fourslash/codeFixWrapDecoratorInParentheses01.ts @@ -0,0 +1,14 @@ +/// + +////declare var x: any; +////class C { +//// @[|x?.y|] +//// bar() { +//// +//// } +////} + +verify.codeFix({ + description: "Wrap in parentheses", + newRangeContent: `(x?.y)` +}); diff --git a/tests/cases/fourslash/codeFixWrapDecoratorInParentheses_all.ts b/tests/cases/fourslash/codeFixWrapDecoratorInParentheses_all.ts new file mode 100644 index 0000000000000..f8d17bda516cc --- /dev/null +++ b/tests/cases/fourslash/codeFixWrapDecoratorInParentheses_all.ts @@ -0,0 +1,24 @@ +/// + +////declare var x: any; +////class C { +//// @x?.y +//// bar() {} +//// +//// @x?.() +//// baz() {} +////} + +verify.codeFixAll({ + fixId: "wrapDecoratorInParentheses", + fixAllDescription: "Wrap all invalid decorator expressions in parentheses", + newFileContent: +`declare var x: any; +class C { + @(x?.y) + bar() {} + + @(x?.()) + baz() {} +}` +}); From 332aadf274c4e700e489c7933070825492bbe00c Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 12 Mar 2024 16:19:08 -0400 Subject: [PATCH 2/3] Formatting --- src/compiler/checker.ts | 2 +- src/services/codefixes/wrapDecoratorInParentheses.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7cc4ba6a2cfe5..e5afd2bb9b336 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -41640,7 +41640,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (errorNode) { addRelatedInfo( error(decorator.expression, Diagnostics.Expression_must_be_enclosed_in_parentheses_to_be_used_as_a_decorator), - createDiagnosticForNode(errorNode, Diagnostics.Invalid_syntax_in_decorator) + createDiagnosticForNode(errorNode, Diagnostics.Invalid_syntax_in_decorator), ); return true; } diff --git a/src/services/codefixes/wrapDecoratorInParentheses.ts b/src/services/codefixes/wrapDecoratorInParentheses.ts index d940f696a799f..10066eebda99f 100644 --- a/src/services/codefixes/wrapDecoratorInParentheses.ts +++ b/src/services/codefixes/wrapDecoratorInParentheses.ts @@ -6,7 +6,7 @@ import { getTokenAtPosition, isDecorator, SourceFile, - textChanges + textChanges, } from "../_namespaces/ts"; import { codeFixAll, From 3526677597e5a1734e0688649fce5d8ce02683a4 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 12 Mar 2024 20:44:26 -0400 Subject: [PATCH 3/3] Additional tests --- src/testRunner/compilerRunner.ts | 53 ++-- ...1(experimentaldecorators=false).errors.txt | 137 ++++++++++ ...ression.1(experimentaldecorators=false).js | 172 ++++++++++++ ....1(experimentaldecorators=true).errors.txt | 137 ++++++++++ ...pression.1(experimentaldecorators=true).js | 216 +++++++++++++++ ...ression.2(experimentaldecorators=false).js | 204 ++++++++++++++ ...pression.2(experimentaldecorators=true).js | 256 ++++++++++++++++++ ...3(experimentaldecorators=false).errors.txt | 23 ++ ...ression.3(experimentaldecorators=false).js | 22 ++ ....3(experimentaldecorators=true).errors.txt | 23 ++ ...pression.3(experimentaldecorators=true).js | 22 ++ .../esDecorators-decoratorExpression.1.ts | 50 ++++ .../esDecorators-decoratorExpression.2.ts | 60 ++++ .../esDecorators-decoratorExpression.3.ts | 12 + 14 files changed, 1361 insertions(+), 26 deletions(-) create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).errors.txt create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).js create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).errors.txt create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).js create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=false).js create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=true).js create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).errors.txt create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).js create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).errors.txt create mode 100644 tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).js create mode 100644 tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts create mode 100644 tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts create mode 100644 tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts diff --git a/src/testRunner/compilerRunner.ts b/src/testRunner/compilerRunner.ts index b5d08ca8f2e03..acd9fc75611c5 100644 --- a/src/testRunner/compilerRunner.ts +++ b/src/testRunner/compilerRunner.ts @@ -128,42 +128,43 @@ export class CompilerBaselineRunner extends RunnerBase { class CompilerTest { private static varyBy: readonly string[] = [ - "module", - "moduleResolution", - "moduleDetection", + "allowArbitraryExtensions", "allowImportingTsExtensions", - "target", - "jsx", - "noEmit", - "removeComments", + "allowSyntheticDefaultImports", + "alwaysStrict", + "downlevelIteration", + "experimentalDecorators", + "emitDecoratorMetadata", + "esModuleInterop", + "exactOptionalPropertyTypes", "importHelpers", "importHelpers", - "downlevelIteration", "isolatedModules", - "verbatimModuleSyntax", - "strict", + "jsx", + "module", + "moduleDetection", + "moduleResolution", + "noEmit", "noImplicitAny", - "strictNullChecks", - "strictFunctionTypes", - "strictBindCallApply", - "strictPropertyInitialization", "noImplicitThis", - "alwaysStrict", - "allowSyntheticDefaultImports", - "esModuleInterop", - "emitDecoratorMetadata", - "skipDefaultLibCheck", + "noPropertyAccessFromIndexSignature", + "noUncheckedIndexedAccess", "preserveConstEnums", + "removeComments", + "resolveJsonModule", + "resolvePackageJsonExports", + "resolvePackageJsonImports", + "skipDefaultLibCheck", "skipLibCheck", - "exactOptionalPropertyTypes", + "strict", + "strictBindCallApply", + "strictFunctionTypes", + "strictNullChecks", + "strictPropertyInitialization", + "target", "useDefineForClassFields", "useUnknownInCatchVariables", - "noUncheckedIndexedAccess", - "noPropertyAccessFromIndexSignature", - "resolvePackageJsonExports", - "resolvePackageJsonImports", - "resolveJsonModule", - "allowArbitraryExtensions", + "verbatimModuleSyntax", ]; private fileName: string; private justName: string; diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).errors.txt b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).errors.txt new file mode 100644 index 0000000000000..4ce2e0fa9ac23 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).errors.txt @@ -0,0 +1,137 @@ +esDecorators-decoratorExpression.1.ts(3,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(5,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(7,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(9,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(11,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(13,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(15,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(17,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(19,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(21,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(23,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(25,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(27,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(29,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(31,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(33,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(35,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(37,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(39,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(41,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(43,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(45,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. + + +==== esDecorators-decoratorExpression.1.ts (22 errors) ==== + declare let x: any; + + { @x().y class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:3:4: Invalid syntax in decorator. + + { @new x class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:5:4: Invalid syntax in decorator. + + { @x().y() class C {} } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:7:4: Invalid syntax in decorator. + + { @x?.y class C {} } + ~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:9:5: Invalid syntax in decorator. + + { @x?.y() class C {} } + ~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:11:5: Invalid syntax in decorator. + + { @x?.["y"] class C {} } + ~~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:13:4: Invalid syntax in decorator. + + { @x?.() class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:15:5: Invalid syntax in decorator. + + { @x`` class C {} } + ~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:17:4: Invalid syntax in decorator. + + { @x``() class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:19:4: Invalid syntax in decorator. + + { @x.y`` class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:21:4: Invalid syntax in decorator. + + { @x.y``() class C {} } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:23:4: Invalid syntax in decorator. + + { class C { @x().y m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:25:14: Invalid syntax in decorator. + + { class C { @new x m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:27:14: Invalid syntax in decorator. + + { class C { @x().y() m() {} } } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:29:14: Invalid syntax in decorator. + + { class C { @x?.y m() {} } } + ~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:31:15: Invalid syntax in decorator. + + { class C { @x?.y() m() {} } } + ~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:33:15: Invalid syntax in decorator. + + { class C { @x?.["y"] m() {} } } + ~~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:35:14: Invalid syntax in decorator. + + { class C { @x?.() m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:37:15: Invalid syntax in decorator. + + { class C { @x`` m() {} } } + ~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:39:14: Invalid syntax in decorator. + + { class C { @x``() m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:41:14: Invalid syntax in decorator. + + { class C { @x.y`` m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:43:14: Invalid syntax in decorator. + + { class C { @x.y``() m() {} } } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:45:14: Invalid syntax in decorator. + \ No newline at end of file diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).js b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).js new file mode 100644 index 0000000000000..b9a4c97f746ad --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=false).js @@ -0,0 +1,172 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts] //// + +//// [esDecorators-decoratorExpression.1.ts] +declare let x: any; + +{ @x().y class C {} } + +{ @new x class C {} } + +{ @x().y() class C {} } + +{ @x?.y class C {} } + +{ @x?.y() class C {} } + +{ @x?.["y"] class C {} } + +{ @x?.() class C {} } + +{ @x`` class C {} } + +{ @x``() class C {} } + +{ @x.y`` class C {} } + +{ @x.y``() class C {} } + +{ class C { @x().y m() {} } } + +{ class C { @new x m() {} } } + +{ class C { @x().y() m() {} } } + +{ class C { @x?.y m() {} } } + +{ class C { @x?.y() m() {} } } + +{ class C { @x?.["y"] m() {} } } + +{ class C { @x?.() m() {} } } + +{ class C { @x`` m() {} } } + +{ class C { @x``() m() {} } } + +{ class C { @x.y`` m() {} } } + +{ class C { @x.y``() m() {} } } + + +//// [esDecorators-decoratorExpression.1.js] +{ + @x().y + class C { + } +} +{ + @new x + class C { + } +} +{ + @x().y() + class C { + } +} +{ + @x?.y + class C { + } +} +{ + @x?.y() + class C { + } +} +{ + @x?.["y"] + class C { + } +} +{ + @x?.() + class C { + } +} +{ + @x `` + class C { + } +} +{ + @x ``() + class C { + } +} +{ + @x.y `` + class C { + } +} +{ + @x.y ``() + class C { + } +} +{ + class C { + @x().y + m() { } + } +} +{ + class C { + @new x + m() { } + } +} +{ + class C { + @x().y() + m() { } + } +} +{ + class C { + @x?.y + m() { } + } +} +{ + class C { + @x?.y() + m() { } + } +} +{ + class C { + @x?.["y"] + m() { } + } +} +{ + class C { + @x?.() + m() { } + } +} +{ + class C { + @x `` + m() { } + } +} +{ + class C { + @x ``() + m() { } + } +} +{ + class C { + @x.y `` + m() { } + } +} +{ + class C { + @x.y ``() + m() { } + } +} diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).errors.txt b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).errors.txt new file mode 100644 index 0000000000000..4ce2e0fa9ac23 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).errors.txt @@ -0,0 +1,137 @@ +esDecorators-decoratorExpression.1.ts(3,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(5,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(7,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(9,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(11,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(13,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(15,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(17,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(19,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(21,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(23,4): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(25,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(27,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(29,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(31,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(33,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(35,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(37,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(39,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(41,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(43,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +esDecorators-decoratorExpression.1.ts(45,14): error TS1497: Expression must be enclosed in parentheses to be used as a decorator. + + +==== esDecorators-decoratorExpression.1.ts (22 errors) ==== + declare let x: any; + + { @x().y class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:3:4: Invalid syntax in decorator. + + { @new x class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:5:4: Invalid syntax in decorator. + + { @x().y() class C {} } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:7:4: Invalid syntax in decorator. + + { @x?.y class C {} } + ~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:9:5: Invalid syntax in decorator. + + { @x?.y() class C {} } + ~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:11:5: Invalid syntax in decorator. + + { @x?.["y"] class C {} } + ~~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:13:4: Invalid syntax in decorator. + + { @x?.() class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:15:5: Invalid syntax in decorator. + + { @x`` class C {} } + ~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:17:4: Invalid syntax in decorator. + + { @x``() class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:19:4: Invalid syntax in decorator. + + { @x.y`` class C {} } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:21:4: Invalid syntax in decorator. + + { @x.y``() class C {} } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:23:4: Invalid syntax in decorator. + + { class C { @x().y m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:25:14: Invalid syntax in decorator. + + { class C { @new x m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:27:14: Invalid syntax in decorator. + + { class C { @x().y() m() {} } } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:29:14: Invalid syntax in decorator. + + { class C { @x?.y m() {} } } + ~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:31:15: Invalid syntax in decorator. + + { class C { @x?.y() m() {} } } + ~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:33:15: Invalid syntax in decorator. + + { class C { @x?.["y"] m() {} } } + ~~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:35:14: Invalid syntax in decorator. + + { class C { @x?.() m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:37:15: Invalid syntax in decorator. + + { class C { @x`` m() {} } } + ~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:39:14: Invalid syntax in decorator. + + { class C { @x``() m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:41:14: Invalid syntax in decorator. + + { class C { @x.y`` m() {} } } + ~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:43:14: Invalid syntax in decorator. + + { class C { @x.y``() m() {} } } + ~~~~~~~ +!!! error TS1497: Expression must be enclosed in parentheses to be used as a decorator. +!!! related TS1498 esDecorators-decoratorExpression.1.ts:45:14: Invalid syntax in decorator. + \ No newline at end of file diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).js b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).js new file mode 100644 index 0000000000000..2e16e04490759 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.1(experimentaldecorators=true).js @@ -0,0 +1,216 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts] //// + +//// [esDecorators-decoratorExpression.1.ts] +declare let x: any; + +{ @x().y class C {} } + +{ @new x class C {} } + +{ @x().y() class C {} } + +{ @x?.y class C {} } + +{ @x?.y() class C {} } + +{ @x?.["y"] class C {} } + +{ @x?.() class C {} } + +{ @x`` class C {} } + +{ @x``() class C {} } + +{ @x.y`` class C {} } + +{ @x.y``() class C {} } + +{ class C { @x().y m() {} } } + +{ class C { @new x m() {} } } + +{ class C { @x().y() m() {} } } + +{ class C { @x?.y m() {} } } + +{ class C { @x?.y() m() {} } } + +{ class C { @x?.["y"] m() {} } } + +{ class C { @x?.() m() {} } } + +{ class C { @x`` m() {} } } + +{ class C { @x``() m() {} } } + +{ class C { @x.y`` m() {} } } + +{ class C { @x.y``() m() {} } } + + +//// [esDecorators-decoratorExpression.1.js] +{ + let C = class C { + }; + C = __decorate([ + x().y + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + new x + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x().y() + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x?.y + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x?.y() + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x?.["y"] + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x?.() + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x `` + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x ``() + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x.y `` + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x.y ``() + ], C); +} +{ + class C { + m() { } + } + __decorate([ + x().y + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + new x + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x().y() + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x?.y + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x?.y() + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x?.["y"] + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x?.() + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x `` + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x ``() + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x.y `` + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x.y ``() + ], C.prototype, "m", null); +} diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=false).js b/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=false).js new file mode 100644 index 0000000000000..5fa5c99b08397 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=false).js @@ -0,0 +1,204 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts] //// + +//// [esDecorators-decoratorExpression.2.ts] +declare let x: any; +declare let g: (...args: any) => any; +declare let h: () => (...args: any) => any; + +{ @x! class C {} } + +{ @x.y! class C {} } + +{ @x!.y class C {} } + +{ @g() class C {} } + +{ @(g) class C {} } + +{ @(h()) class C {} } + +{ @(x().y) class C {} } + +{ @(x().y()) class C {} } + +{ @(x``) class C {} } + +{ @(x.y``) class C {} } + +{ @(x?.y!) class C {} } + +{ @(x["y"]) class C {} } + +{ @(x?.["y"]) class C {} } + +{ class C { @x! m() {} } } + +{ class C { @x.y! m() {} } } + +{ class C { @x!.y m() {} } } + +{ class C { @g() m() {} } } + +{ class C { @(g) m() {} } } + +{ class C { @(h()) m() {} } } + +{ class C { @(x().y) m() {} } } + +{ class C { @(x().y()) m() {} } } + +{ class C { @(x``) m() {} } } + +{ class C { @(x.y``) m() {} } } + +{ class C { @(x?.y!) m() {} } } + +{ class C { @(x["y"]) m() {} } } + +{ class C { @(x?.["y"]) m() {} } } + + +//// [esDecorators-decoratorExpression.2.js] +{ + @x + class C { + } +} +{ + @x.y + class C { + } +} +{ + @x.y + class C { + } +} +{ + @g() + class C { + } +} +{ + @(g) + class C { + } +} +{ + @(h()) + class C { + } +} +{ + @(x().y) + class C { + } +} +{ + @(x().y()) + class C { + } +} +{ + @(x ``) + class C { + } +} +{ + @(x.y ``) + class C { + } +} +{ + @(x?.y) + class C { + } +} +{ + @(x["y"]) + class C { + } +} +{ + @(x?.["y"]) + class C { + } +} +{ + class C { + @x + m() { } + } +} +{ + class C { + @x.y + m() { } + } +} +{ + class C { + @x.y + m() { } + } +} +{ + class C { + @g() + m() { } + } +} +{ + class C { + @(g) + m() { } + } +} +{ + class C { + @(h()) + m() { } + } +} +{ + class C { + @(x().y) + m() { } + } +} +{ + class C { + @(x().y()) + m() { } + } +} +{ + class C { + @(x ``) + m() { } + } +} +{ + class C { + @(x.y ``) + m() { } + } +} +{ + class C { + @(x?.y) + m() { } + } +} +{ + class C { + @(x["y"]) + m() { } + } +} +{ + class C { + @(x?.["y"]) + m() { } + } +} diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=true).js b/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=true).js new file mode 100644 index 0000000000000..d82dde020ffcc --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.2(experimentaldecorators=true).js @@ -0,0 +1,256 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts] //// + +//// [esDecorators-decoratorExpression.2.ts] +declare let x: any; +declare let g: (...args: any) => any; +declare let h: () => (...args: any) => any; + +{ @x! class C {} } + +{ @x.y! class C {} } + +{ @x!.y class C {} } + +{ @g() class C {} } + +{ @(g) class C {} } + +{ @(h()) class C {} } + +{ @(x().y) class C {} } + +{ @(x().y()) class C {} } + +{ @(x``) class C {} } + +{ @(x.y``) class C {} } + +{ @(x?.y!) class C {} } + +{ @(x["y"]) class C {} } + +{ @(x?.["y"]) class C {} } + +{ class C { @x! m() {} } } + +{ class C { @x.y! m() {} } } + +{ class C { @x!.y m() {} } } + +{ class C { @g() m() {} } } + +{ class C { @(g) m() {} } } + +{ class C { @(h()) m() {} } } + +{ class C { @(x().y) m() {} } } + +{ class C { @(x().y()) m() {} } } + +{ class C { @(x``) m() {} } } + +{ class C { @(x.y``) m() {} } } + +{ class C { @(x?.y!) m() {} } } + +{ class C { @(x["y"]) m() {} } } + +{ class C { @(x?.["y"]) m() {} } } + + +//// [esDecorators-decoratorExpression.2.js] +{ + let C = class C { + }; + C = __decorate([ + x + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x.y + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + x.y + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + g() + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (g) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (h()) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x().y) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x().y()) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x ``) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x.y ``) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x?.y) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x["y"]) + ], C); +} +{ + let C = class C { + }; + C = __decorate([ + (x?.["y"]) + ], C); +} +{ + class C { + m() { } + } + __decorate([ + x + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x.y + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + x.y + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + g() + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (g) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (h()) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x().y) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x().y()) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x ``) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x.y ``) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x?.y) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x["y"]) + ], C.prototype, "m", null); +} +{ + class C { + m() { } + } + __decorate([ + (x?.["y"]) + ], C.prototype, "m", null); +} diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).errors.txt b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).errors.txt new file mode 100644 index 0000000000000..933ff95f0ff32 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).errors.txt @@ -0,0 +1,23 @@ +esDecorators-decoratorExpression.3.ts(5,5): error TS1146: Declaration expected. +esDecorators-decoratorExpression.3.ts(5,5): error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +esDecorators-decoratorExpression.3.ts(7,7): error TS1146: Declaration expected. +esDecorators-decoratorExpression.3.ts(7,7): error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + + +==== esDecorators-decoratorExpression.3.ts (4 errors) ==== + declare let g: (...args: any) => any; + + // existing errors + + { @g class C {} } + +!!! error TS1146: Declaration expected. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + + { @g() class C {} } + +!!! error TS1146: Declaration expected. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + \ No newline at end of file diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).js b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).js new file mode 100644 index 0000000000000..8e1fc64d2be55 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=false).js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts] //// + +//// [esDecorators-decoratorExpression.3.ts] +declare let g: (...args: any) => any; + +// existing errors + +{ @g class C {} } + +{ @g() class C {} } + + +//// [esDecorators-decoratorExpression.3.js] +// existing errors +{ + class C { + }; +} +{ + class C { + }; +} diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).errors.txt b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).errors.txt new file mode 100644 index 0000000000000..933ff95f0ff32 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).errors.txt @@ -0,0 +1,23 @@ +esDecorators-decoratorExpression.3.ts(5,5): error TS1146: Declaration expected. +esDecorators-decoratorExpression.3.ts(5,5): error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +esDecorators-decoratorExpression.3.ts(7,7): error TS1146: Declaration expected. +esDecorators-decoratorExpression.3.ts(7,7): error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + + +==== esDecorators-decoratorExpression.3.ts (4 errors) ==== + declare let g: (...args: any) => any; + + // existing errors + + { @g class C {} } + +!!! error TS1146: Declaration expected. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + + { @g() class C {} } + +!!! error TS1146: Declaration expected. + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Conversion of type 'typeof C' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + \ No newline at end of file diff --git a/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).js b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).js new file mode 100644 index 0000000000000..8e1fc64d2be55 --- /dev/null +++ b/tests/baselines/reference/esDecorators-decoratorExpression.3(experimentaldecorators=true).js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts] //// + +//// [esDecorators-decoratorExpression.3.ts] +declare let g: (...args: any) => any; + +// existing errors + +{ @g class C {} } + +{ @g() class C {} } + + +//// [esDecorators-decoratorExpression.3.js] +// existing errors +{ + class C { + }; +} +{ + class C { + }; +} diff --git a/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts new file mode 100644 index 0000000000000..a10fee8e1fd4d --- /dev/null +++ b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.1.ts @@ -0,0 +1,50 @@ +// @target: esnext +// @experimentalDecorators: * +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +declare let x: any; + +{ @x().y class C {} } + +{ @new x class C {} } + +{ @x().y() class C {} } + +{ @x?.y class C {} } + +{ @x?.y() class C {} } + +{ @x?.["y"] class C {} } + +{ @x?.() class C {} } + +{ @x`` class C {} } + +{ @x``() class C {} } + +{ @x.y`` class C {} } + +{ @x.y``() class C {} } + +{ class C { @x().y m() {} } } + +{ class C { @new x m() {} } } + +{ class C { @x().y() m() {} } } + +{ class C { @x?.y m() {} } } + +{ class C { @x?.y() m() {} } } + +{ class C { @x?.["y"] m() {} } } + +{ class C { @x?.() m() {} } } + +{ class C { @x`` m() {} } } + +{ class C { @x``() m() {} } } + +{ class C { @x.y`` m() {} } } + +{ class C { @x.y``() m() {} } } diff --git a/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts new file mode 100644 index 0000000000000..807cec63f57e9 --- /dev/null +++ b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.2.ts @@ -0,0 +1,60 @@ +// @target: esnext +// @experimentalDecorators: * +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +declare let x: any; +declare let g: (...args: any) => any; +declare let h: () => (...args: any) => any; + +{ @x! class C {} } + +{ @x.y! class C {} } + +{ @x!.y class C {} } + +{ @g() class C {} } + +{ @(g) class C {} } + +{ @(h()) class C {} } + +{ @(x().y) class C {} } + +{ @(x().y()) class C {} } + +{ @(x``) class C {} } + +{ @(x.y``) class C {} } + +{ @(x?.y!) class C {} } + +{ @(x["y"]) class C {} } + +{ @(x?.["y"]) class C {} } + +{ class C { @x! m() {} } } + +{ class C { @x.y! m() {} } } + +{ class C { @x!.y m() {} } } + +{ class C { @g() m() {} } } + +{ class C { @(g) m() {} } } + +{ class C { @(h()) m() {} } } + +{ class C { @(x().y) m() {} } } + +{ class C { @(x().y()) m() {} } } + +{ class C { @(x``) m() {} } } + +{ class C { @(x.y``) m() {} } } + +{ class C { @(x?.y!) m() {} } } + +{ class C { @(x["y"]) m() {} } } + +{ class C { @(x?.["y"]) m() {} } } diff --git a/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts new file mode 100644 index 0000000000000..69f7039abd7fc --- /dev/null +++ b/tests/cases/conformance/esDecorators/esDecorators-decoratorExpression.3.ts @@ -0,0 +1,12 @@ +// @target: esnext +// @experimentalDecorators: * +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +declare let g: (...args: any) => any; + +// existing errors + +{ @g class C {} } + +{ @g() class C {} }