Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/typescript/src/ast/ast.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ export type ModuleExportName = Identifier | StringLiteral;
export type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral;
export type ModuleBody = ModuleBlock | ModuleDeclaration;
export type JSDocFullName = Identifier | ModuleDeclaration;
export type ForInitializer = Expression | MissingDeclaration | VariableDeclarationList;
export type ForInitializer = Expression | VariableDeclarationList;
export type ModuleReference = Identifier | QualifiedName | ExternalModuleReference;
export type NamedImportBindings = NamespaceImport | NamedImports;
export type NamedExportBindings = NamespaceExport | NamedExports;
Expand Down
1 change: 0 additions & 1 deletion packages/typescript/src/ast/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ function isLeftHandSideExpressionKind(kind: SyntaxKind): boolean {
case SyntaxKind.ExpressionWithTypeArguments:
case SyntaxKind.MetaProperty:
case SyntaxKind.ImportKeyword: // technically this is only an Expression if it's in a CallExpression
case SyntaxKind.MissingDeclaration:
return true;
default:
return false;
Expand Down
1 change: 0 additions & 1 deletion tools/scripts/tsc/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -5236,7 +5236,6 @@
],
"ForInitializer": [
"Expression",
"MissingDeclaration",
"VariableDeclarationList"
],
"ModuleReference": [
Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/ast/ast_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tsc/internal/ast/precedence.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ func GetOperatorPrecedence(nodeKind Kind, operatorKind Kind, flags OperatorPrece
KindOmittedExpression,
KindJsxElement,
KindJsxSelfClosingElement,
KindJsxFragment,
KindMissingDeclaration:
KindJsxFragment:
return OperatorPrecedencePrimary

// !!! By necessity, this differs from the old compiler to support emit. consider backporting
Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func isLeftHandSideExpressionKind(kind Kind) bool {
KindPrivateIdentifier, KindRegularExpressionLiteral, KindNumericLiteral, KindBigIntLiteral, KindStringLiteral,
KindNoSubstitutionTemplateLiteral, KindTemplateExpression, KindFalseKeyword, KindNullKeyword, KindThisKeyword,
KindTrueKeyword, KindSuperKeyword, KindNonNullExpression, KindExpressionWithTypeArguments, KindMetaProperty,
KindImportKeyword, KindMissingDeclaration:
KindImportKeyword:
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5905,7 +5905,7 @@ func (p *Parser) parseDecoratedExpression() *ast.Expression {
return p.parseClassDeclarationOrExpression(pos, jsdoc, modifiers, ast.KindClassExpression)
}
p.parseErrorAt(p.nodePos(), p.nodePos(), diagnostics.Expression_expected)
return p.finishNode(p.factory.NewMissingDeclaration(modifiers), pos)
return p.createMissingIdentifier()
}

func (p *Parser) unparseExpressionWithTypeArguments(expression *ast.Node, typeArguments *ast.NodeList, result *ast.Node) {
Expand Down
2 changes: 0 additions & 2 deletions tsc/internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3312,8 +3312,6 @@ func (p *Printer) emitExpression(node *ast.Expression, precedence ast.OperatorPr
p.emitMetaProperty(node.AsMetaProperty())
case ast.KindSyntheticExpression:
panic("SyntheticExpression should never be printed.")
case ast.KindMissingDeclaration:
// Missing declarations do not emit an expression.

// JSX
case ast.KindJsxElement:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
assignment.ts(2,9): error TS1109: Expression expected.
assignment.ts(2,10): error TS1005: ';' expected.
assignment.ts(3,8): error TS1109: Expression expected.
assignment.ts(3,9): error TS1005: ';' expected.
destructuring.ts(1,8): error TS1109: Expression expected.
forAwait.ts(2,18): error TS1109: Expression expected.


==== assignment.ts (4 errors) ====
let x;
x = @dec 1;

!!! error TS1109: Expression expected.
~
!!! error TS1005: ';' expected.
x = @@a 1;

!!! error TS1109: Expression expected.
~
!!! error TS1005: ';' expected.

==== forAwait.ts (1 errors) ====
async function f(y: any) {
for await (@d of y) {}

!!! error TS1109: Expression expected.
}

==== destructuring.ts (1 errors) ====
({...@d} = {});

!!! error TS1109: Expression expected.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//// [tests/cases/compiler/decoratorMissingClassExpression.ts] ////

//// [assignment.ts]
let x;
x = @dec 1;
x = @@a 1;

//// [forAwait.ts]
async function f(y: any) {
for await (@d of y) {}
}

//// [destructuring.ts]
({...@d} = {});


//// [assignment.js]
"use strict";
let x;
x = ;
1;
x = ;
1;
//// [forAwait.js]
"use strict";
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
async function f(y) {
var _a, e_1, _b, _c;
try {
for (var _d = true, y_1 = __asyncValues(y), y_1_1; y_1_1 = await y_1.next(), _a = y_1_1.done, !_a; _d = true) {
_c = y_1_1.value;
_d = false;
= _c;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = y_1.return)) await _b.call(y_1);
}
finally { if (e_1) throw e_1.error; }
}
}
//// [destructuring.js]
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
( = __rest({}, []));
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/decoratorMissingClassExpression.ts] ////

=== assignment.ts ===
let x;
>x : Symbol(x, Decl(assignment.ts, 0, 3))

x = @dec 1;
>x : Symbol(x, Decl(assignment.ts, 0, 3))

x = @@a 1;
>x : Symbol(x, Decl(assignment.ts, 0, 3))

=== forAwait.ts ===
async function f(y: any) {
>f : Symbol(f, Decl(forAwait.ts, 0, 0))
>y : Symbol(y, Decl(forAwait.ts, 0, 17))

for await (@d of y) {}
>y : Symbol(y, Decl(forAwait.ts, 0, 17))
}

=== destructuring.ts ===

({...@d} = {});

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [tests/cases/compiler/decoratorMissingClassExpression.ts] ////

=== assignment.ts ===
let x;
>x : any

x = @dec 1;
>x = @dec : any
>x : any
> : any
>1 : 1

x = @@a 1;
>x = @@a : any
>x : any
> : any
>1 : 1

=== forAwait.ts ===
async function f(y: any) {
>f : (y: any) => Promise<void>
>y : any

for await (@d of y) {}
> : any
>y : any
}

=== destructuring.ts ===
({...@d} = {});
>({...@d} = {}) : {}
>{...@d} = {} : {}
>{...@d} : any
> : any
>{} : {}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
decoratorOnArrowFunction.ts(3,16): error TS1109: Expression expected.
decoratorOnArrowFunction.ts(3,17): error TS1005: ';' expected.
decoratorOnArrowFunction.ts(3,16): error TS7006: Parameter '(Missing)' implicitly has an 'any' type.


==== decoratorOnArrowFunction.ts (2 errors) ====
Expand All @@ -8,6 +8,6 @@ decoratorOnArrowFunction.ts(3,17): error TS1005: ';' expected.
var F = @dec () => {

!!! error TS1109: Expression expected.
~~
!!! error TS1005: ';' expected.

!!! error TS7006: Parameter '(Missing)' implicitly has an 'any' type.
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ var F = @dec () => {

//// [decoratorOnArrowFunction.js]
"use strict";
var F = ;
{
}
var F = () => {
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ declare function dec<T>(target: T): T;

var F = @dec () => {
>F : Symbol(F, Decl(decoratorOnArrowFunction.ts, 2, 3))
>dec : Symbol(dec, Decl(decoratorOnArrowFunction.ts, 0, 0))
> : Symbol((Missing), Decl(decoratorOnArrowFunction.ts, 2, 15))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare function dec<T>(target: T): T;
>target : T

var F = @dec () => {
>F : any
>dec () : unknown
>dec : <T>(target: T) => T
>F : (: any) => void
>@dec () => {} : (: any) => void
> : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ declare function dec<T>(target: T): T;

var F = @dec function () {
>F : Symbol(F, Decl(decoratorOnFunctionExpression.ts, 2, 3))
>dec : Symbol(dec, Decl(decoratorOnFunctionExpression.ts, 0, 0))
> : Symbol((Missing), Decl(decoratorOnFunctionExpression.ts, 2, 12))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ declare function dec<T>(target: T): T;

var F = @dec function () {
>F : any
>dec : <T>(target: T) => T
> : any
> : () => void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @target: es2017
// @lib: esnext

// @filename: assignment.ts
let x;
x = @dec 1;
x = @@a 1;

// @filename: forAwait.ts
async function f(y: any) {
for await (@d of y) {}
}

// @filename: destructuring.ts
({...@d} = {});
Loading