@@ -2475,6 +2475,10 @@ func (c *Checker) checkTypeParameterDeferred(node *ast.Node) {
24752475 }
24762476}
24772477
2478+ func (c *Checker) shouldCheckErasableSyntax(node *ast.Node) bool {
2479+ return c.compilerOptions.ErasableSyntaxOnly.IsTrue() && !ast.IsInJSFile(node)
2480+ }
2481+
24782482func (c *Checker) checkParameter(node *ast.Node) {
24792483 // Grammar checking
24802484 // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
@@ -2488,7 +2492,7 @@ func (c *Checker) checkParameter(node *ast.Node) {
24882492 paramName = node.Name().Text()
24892493 }
24902494 if ast.HasSyntacticModifier(node, ast.ModifierFlagsParameterPropertyModifier) {
2491- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) {
2495+ if c.shouldCheckErasableSyntax(node ) {
24922496 c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
24932497 }
24942498 if !(ast.IsConstructorDeclaration(fn) && ast.NodeIsPresent(fn.Body())) {
@@ -4840,7 +4844,7 @@ func (c *Checker) checkEnumDeclaration(node *ast.Node) {
48404844 c.checkExportsOnMergedDeclarations(node)
48414845 c.checkSourceElements(node.Members())
48424846
4843- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) && node.Flags&ast.NodeFlagsAmbient == 0 {
4847+ if c.shouldCheckErasableSyntax(node ) && node.Flags&ast.NodeFlagsAmbient == 0 {
48444848 c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
48454849 }
48464850
@@ -4930,7 +4934,7 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) {
49304934 symbol := c.getSymbolOfDeclaration(node)
49314935 // The following checks only apply on a non-ambient instantiated module declaration.
49324936 if symbol.Flags&ast.SymbolFlagsValueModule != 0 && !inAmbientContext && isInstantiatedModule(node, c.compilerOptions.ShouldPreserveConstEnums()) {
4933- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) {
4937+ if c.shouldCheckErasableSyntax(node ) {
49344938 c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
49354939 }
49364940 if c.compilerOptions.GetIsolatedModules() && ast.GetSourceFileOfNode(node).ExternalModuleIndicator == nil {
@@ -5229,7 +5233,7 @@ func (c *Checker) checkImportEqualsDeclaration(node *ast.Node) {
52295233 return // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
52305234 }
52315235 c.checkGrammarModifiers(node)
5232- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) && node.Flags&ast.NodeFlagsAmbient == 0 {
5236+ if c.shouldCheckErasableSyntax(node ) && node.Flags&ast.NodeFlagsAmbient == 0 {
52335237 c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
52345238 }
52355239 if ast.IsInternalModuleImportEqualsDeclaration(node) || c.checkExternalImportOrExportDeclaration(node) {
@@ -5331,7 +5335,7 @@ func (c *Checker) checkExportAssignment(node *ast.Node) {
53315335 if c.checkGrammarModuleElementContext(node, illegalContextMessage) {
53325336 return // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
53335337 }
5334- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) && node.AsExportAssignment().IsExportEquals && node.Flags&ast.NodeFlagsAmbient == 0 {
5338+ if c.shouldCheckErasableSyntax(node ) && node.AsExportAssignment().IsExportEquals && node.Flags&ast.NodeFlagsAmbient == 0 {
53355339 c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
53365340 }
53375341 container := node.Parent
@@ -11810,7 +11814,7 @@ func (c *Checker) classDeclarationExtendsNull(classDecl *ast.Node) bool {
1181011814
1181111815func (c *Checker) checkAssertion(node *ast.Node, checkMode CheckMode) *Type {
1181211816 if node.Kind == ast.KindTypeAssertionExpression {
11813- if c.compilerOptions.ErasableSyntaxOnly.IsTrue( ) {
11817+ if c.shouldCheckErasableSyntax(node ) {
1181411818 c.diagnostics.Add(ast.NewDiagnostic(ast.GetSourceFileOfNode(node), core.NewTextRange(scanner.SkipTrivia(ast.GetSourceFileOfNode(node).Text(), node.Pos()), node.Expression().Pos()), diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled))
1181511819 }
1181611820 }
0 commit comments