@@ -28,6 +28,16 @@ func expectParseErrorExperimentalDecoratorTS(t *testing.T, contents string, expe
2828 })
2929}
3030
31+ func expectParseErrorWithUnsupportedFeaturesTS (t * testing.T , unsupportedJSFeatures compat.JSFeature , contents string , expected string ) {
32+ t .Helper ()
33+ expectParseErrorCommon (t , contents , expected , config.Options {
34+ TS : config.TSOptions {
35+ Parse : true ,
36+ },
37+ UnsupportedJSFeatures : unsupportedJSFeatures ,
38+ })
39+ }
40+
3141func expectParseErrorTargetTS (t * testing.T , esVersion int , contents string , expected string ) {
3242 t .Helper ()
3343 expectParseErrorCommon (t , contents , expected , config.Options {
@@ -1825,15 +1835,6 @@ func TestTSDeclare(t *testing.T) {
18251835}
18261836
18271837func TestTSExperimentalDecorator (t * testing.T ) {
1828- expectPrintedTS (t , "@dec class Foo {}" , "@dec\n class Foo {\n }\n " )
1829- expectPrintedTS (t , "class Foo { @dec foo: any }" , "class Foo {\n @dec\n foo;\n }\n " )
1830- expectPrintedTS (t , "class Foo { @dec foo(): any {} }" , "class Foo {\n @dec\n foo() {\n }\n }\n " )
1831- expectPrintedTS (t , "class Foo { @dec static foo: any }" , "class Foo {\n @dec\n static foo;\n }\n " )
1832- expectPrintedTS (t , "class Foo { @dec static foo(): any {} }" , "class Foo {\n @dec\n static foo() {\n }\n }\n " )
1833- expectParseErrorTS (t , "class Foo { @dec static {} }" , "<stdin>: ERROR: Expected \" ;\" but found \" {\" \n " )
1834- expectParseErrorTS (t , "class Foo { foo(@dec bar): any }" , "<stdin>: ERROR: Parameter decorators only work when experimental decorators are enabled\n " +
1835- "NOTE: You can enable experimental decorators by adding \" experimentalDecorators\" : true to your \" tsconfig.json\" file.\n " )
1836-
18371838 // Tests of "declare class"
18381839 expectPrintedExperimentalDecoratorTS (t , "@dec(() => 0) declare class Foo {} {let foo}" , "{\n let foo;\n }\n " )
18391840 expectPrintedExperimentalDecoratorTS (t , "@dec(() => 0) declare abstract class Foo {} {let foo}" , "{\n let foo;\n }\n " )
@@ -1971,6 +1972,38 @@ func TestTSExperimentalDecorator(t *testing.T) {
19711972 expectParseErrorExperimentalDecoratorTS (t , "class Foo { @dec static {} }" , "<stdin>: ERROR: Expected \" ;\" but found \" {\" \n " )
19721973}
19731974
1975+ func TestTSDecorators (t * testing.T ) {
1976+ expectPrintedTS (t , "@x @y class Foo {}" , "@x\n @y\n class Foo {\n }\n " )
1977+ expectPrintedTS (t , "@x @y export class Foo {}" , "@x\n @y\n export class Foo {\n }\n " )
1978+ expectPrintedTS (t , "@x @y export default class Foo {}" , "@x\n @y\n export default class Foo {\n }\n " )
1979+ expectPrintedTS (t , "_ = @x @y class {}" , "_ = @x @y class {\n };\n " )
1980+
1981+ expectPrintedTS (t , "class Foo { @x y: any }" , "class Foo {\n @x\n y;\n }\n " )
1982+ expectPrintedTS (t , "class Foo { @x y(): any {} }" , "class Foo {\n @x\n y() {\n }\n }\n " )
1983+ expectPrintedTS (t , "class Foo { @x static y: any }" , "class Foo {\n @x\n static y;\n }\n " )
1984+ expectPrintedTS (t , "class Foo { @x static y(): any {} }" , "class Foo {\n @x\n static y() {\n }\n }\n " )
1985+ expectPrintedTS (t , "class Foo { @x accessor y: any }" , "class Foo {\n @x\n accessor y;\n }\n " )
1986+
1987+ expectPrintedTS (t , "class Foo { @x #y: any }" , "class Foo {\n @x\n #y;\n }\n " )
1988+ expectPrintedTS (t , "class Foo { @x #y(): any {} }" , "class Foo {\n @x\n #y() {\n }\n }\n " )
1989+ expectPrintedTS (t , "class Foo { @x static #y: any }" , "class Foo {\n @x\n static #y;\n }\n " )
1990+ expectPrintedTS (t , "class Foo { @x static #y(): any {} }" , "class Foo {\n @x\n static #y() {\n }\n }\n " )
1991+ expectPrintedTS (t , "class Foo { @x accessor #y: any }" , "class Foo {\n @x\n accessor #y;\n }\n " )
1992+
1993+ expectParseErrorTS (t , "class Foo { x(@y z) {} }" , "<stdin>: ERROR: Parameter decorators only work when experimental decorators are enabled\n " +
1994+ "NOTE: You can enable experimental decorators by adding \" experimentalDecorators\" : true to your \" tsconfig.json\" file.\n " )
1995+ expectParseErrorTS (t , "class Foo { @x static {} }" , "<stdin>: ERROR: Expected \" ;\" but found \" {\" \n " )
1996+
1997+ errorText := "<stdin>: ERROR: Transforming JavaScript decorators to the configured target environment is not supported yet\n "
1998+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "@dec class Foo {}" , errorText )
1999+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec x }" , errorText )
2000+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec x() {} }" , errorText )
2001+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec accessor x }" , errorText )
2002+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec static x }" , errorText )
2003+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec static x() {} }" , errorText )
2004+ expectParseErrorWithUnsupportedFeaturesTS (t , compat .Decorators , "class Foo { @dec static accessor x }" , errorText )
2005+ }
2006+
19742007func TestTSTry (t * testing.T ) {
19752008 expectPrintedTS (t , "try {} catch (x: any) {}" , "try {\n } catch (x) {\n }\n " )
19762009 expectPrintedTS (t , "try {} catch (x: unknown) {}" , "try {\n } catch (x) {\n }\n " )
0 commit comments