Skip to content

Commit 7edc83d

Browse files
committed
reword an experimental decorators error message
1 parent f3d5352 commit 7edc83d

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

internal/js_parser/js_parser.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6567,10 +6567,10 @@ func (p *parser) parseDecorators(decoratorScope *js_ast.Scope, classKeyword logg
65676567
if p.options.ts.Parse {
65686568
if p.options.ts.Config.ExperimentalDecorators == config.True {
65696569
if (context & decoratorInClassExpr) != 0 {
6570-
p.lexer.AddRangeErrorWithNotes(p.lexer.Range(), "Experimental decorators can only be used with class declarations in TypeScript",
6570+
p.lexer.AddRangeErrorWithNotes(p.lexer.Range(), "TypeScript experimental decorators can only be used with class declarations",
65716571
[]logger.MsgData{p.tracker.MsgData(classKeyword, "This is a class expression, not a class declaration:")})
65726572
} else if (context & decoratorBeforeClassExpr) != 0 {
6573-
p.log.AddError(&p.tracker, p.lexer.Range(), "Experimental decorators cannot be used in expression position in TypeScript")
6573+
p.log.AddError(&p.tracker, p.lexer.Range(), "TypeScript experimental decorators cannot be used in expression position")
65746574
}
65756575
} else {
65766576
if (context&decoratorInFnArgs) != 0 && p.options.ts.Config.ExperimentalDecorators != config.True {
@@ -11251,7 +11251,8 @@ func (p *parser) visitDecorators(decorators []js_ast.Decorator, decoratorScope *
1125111251
if decorators != nil {
1125211252
// Decorators cause us to temporarily revert to the scope that encloses the
1125311253
// class declaration, since that's where the generated code for decorators
11254-
// will be inserted.
11254+
// will be inserted. I believe this currently only matters for parameter
11255+
// decorators, where the scope should not be within the argument list.
1125511256
oldScope := p.currentScope
1125611257
p.currentScope = decoratorScope
1125711258

internal/js_parser/ts_parser_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,9 +1890,9 @@ func TestTSExperimentalDecorator(t *testing.T) {
18901890

18911891
// Decorators must be forbidden outside class statements
18921892
note := "<stdin>: NOTE: This is a class expression, not a class declaration:\n"
1893-
expectParseErrorExperimentalDecoratorTS(t, "(class { @dec foo })", "<stdin>: ERROR: Experimental decorators can only be used with class declarations in TypeScript\n"+note)
1894-
expectParseErrorExperimentalDecoratorTS(t, "(class { @dec foo() {} })", "<stdin>: ERROR: Experimental decorators can only be used with class declarations in TypeScript\n"+note)
1895-
expectParseErrorExperimentalDecoratorTS(t, "(class { foo(@dec x) {} })", "<stdin>: ERROR: Experimental decorators can only be used with class declarations in TypeScript\n"+note)
1893+
expectParseErrorExperimentalDecoratorTS(t, "(class { @dec foo })", "<stdin>: ERROR: TypeScript experimental decorators can only be used with class declarations\n"+note)
1894+
expectParseErrorExperimentalDecoratorTS(t, "(class { @dec foo() {} })", "<stdin>: ERROR: TypeScript experimental decorators can only be used with class declarations\n"+note)
1895+
expectParseErrorExperimentalDecoratorTS(t, "(class { foo(@dec x) {} })", "<stdin>: ERROR: TypeScript experimental decorators can only be used with class declarations\n"+note)
18961896
expectParseErrorExperimentalDecoratorTS(t, "({ @dec foo })", "<stdin>: ERROR: Expected identifier but found \"@\"\n")
18971897
expectParseErrorExperimentalDecoratorTS(t, "({ @dec foo() {} })", "<stdin>: ERROR: Expected identifier but found \"@\"\n")
18981898
expectParseErrorExperimentalDecoratorTS(t, "({ foo(@dec x) {} })", "<stdin>: ERROR: Expected identifier but found \"@\"\n")
@@ -2007,7 +2007,7 @@ func TestTSExperimentalDecorator(t *testing.T) {
20072007
expectParseErrorExperimentalDecoratorTS(t, "@x[y] class Foo {}", "<stdin>: ERROR: Expected \";\" but found \"class\"\n")
20082008
expectParseErrorExperimentalDecoratorTS(t, "@() => {} class Foo {}", "<stdin>: ERROR: Unexpected \")\"\n")
20092009
expectParseErrorExperimentalDecoratorTS(t, "x = @y function() {}",
2010-
"<stdin>: ERROR: Experimental decorators cannot be used in expression position in TypeScript\n"+
2010+
"<stdin>: ERROR: TypeScript experimental decorators cannot be used in expression position\n"+
20112011
"<stdin>: ERROR: Expected \"class\" but found \"function\"\n")
20122012

20132013
// Check ASI for "abstract"
@@ -2023,8 +2023,8 @@ func TestTSExperimentalDecorator(t *testing.T) {
20232023
"let stdin_default = class {\n};\nstdin_default = __decorateClass([\n x\n], stdin_default);\nexport {\n stdin_default as default\n};\n")
20242024
expectPrintedExperimentalDecoratorTS(t, "@x export default class Foo {}", "let Foo = class {\n};\nFoo = __decorateClass([\n x\n], Foo);\nexport {\n Foo as default\n};\n")
20252025
expectPrintedExperimentalDecoratorTS(t, "export default @x class Foo {}", "let Foo = class {\n};\nFoo = __decorateClass([\n x\n], Foo);\nexport {\n Foo as default\n};\n")
2026-
expectParseErrorExperimentalDecoratorTS(t, "export default (@x class {})", "<stdin>: ERROR: Experimental decorators cannot be used in expression position in TypeScript\n")
2027-
expectParseErrorExperimentalDecoratorTS(t, "export default (@x class Foo {})", "<stdin>: ERROR: Experimental decorators cannot be used in expression position in TypeScript\n")
2026+
expectParseErrorExperimentalDecoratorTS(t, "export default (@x class {})", "<stdin>: ERROR: TypeScript experimental decorators cannot be used in expression position\n")
2027+
expectParseErrorExperimentalDecoratorTS(t, "export default (@x class Foo {})", "<stdin>: ERROR: TypeScript experimental decorators cannot be used in expression position\n")
20282028
expectParseErrorExperimentalDecoratorTS(t, "export @x default class {}", "<stdin>: ERROR: Unexpected \"default\"\n")
20292029
expectParseErrorExperimentalDecoratorTS(t, "@x export @y class Foo {}", "<stdin>: ERROR: Decorators are not valid here\n")
20302030
expectParseErrorExperimentalDecoratorTS(t, "@x export default abstract", "<stdin>: ERROR: Decorators are not valid here\n")

0 commit comments

Comments
 (0)