Skip to content

Commit 517545f

Browse files
frigus02copybara-github
authored andcommitted
Fix go/ts52upgrade JSC_INJECT_IN_NON_GLOBAL_OR_BLOCK_ERROR issue
For decorated classes, that reference the class name in a static block, TypeScript 5.2 changed the JS emit from let Foo = class Foo { /** * @ngInject * @param {?} $state */ constructor(state) {} }; to var Foo_1; let Foo = Foo_1 = class Foo { /** * @ngInject * @param {?} $state */ constructor(state) {} }; This broke the enclosing scope detection in the AngularPass. This CL fixes it. PiperOrigin-RevId: 561273919
1 parent b1663e6 commit 517545f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/com/google/javascript/jscomp/AngularPass.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ private void addNode(Node n) {
271271
name = NodeUtil.getName(classNode);
272272
}
273273
fn = n.getFirstChild();
274-
if (classNode.getParent().isAssign() || classNode.getParent().isName()) {
275-
injectAfter = classNode.getGrandparent();
276-
} else {
277-
injectAfter = classNode;
278-
}
274+
injectAfter = NodeUtil.getEnclosingStatement(classNode);
279275
}
280276
break;
281277
default:

test/com/google/javascript/jscomp/AngularPassTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,27 @@ public void testInGoogScope() {
525525
"/** @public */ fn['$inject'] = ['a', 'b'];",
526526
"});"));
527527
}
528+
529+
@Test
530+
public void testNameDeclarationAndAssign() {
531+
test(
532+
lines(
533+
"let A = A_1 = class A {",
534+
" /**",
535+
" * @ngInject",
536+
" * @param {?} foo",
537+
" */",
538+
" constructor(foo) {}",
539+
"};"),
540+
lines(
541+
"let A = A_1 = class A {",
542+
" /**",
543+
" * @ngInject",
544+
" * @param {?} foo",
545+
" */",
546+
" constructor(foo) {}",
547+
"};",
548+
"/** @public */",
549+
"A_1[\"$inject\"] = [\"foo\"];"));
550+
}
528551
}

0 commit comments

Comments
 (0)