@@ -427,26 +427,20 @@ function buildPrecompileOptions<EnvSpecificOptions>(
427
427
}
428
428
429
429
function remapAndBindIdentifiers ( target : NodePath , babel : typeof Babel , scopeLocals : ScopeLocals ) {
430
- babel . traverse (
431
- target . node ,
432
- {
433
- Identifier ( path : NodePath < t . Identifier > ) {
434
- if ( scopeLocals . has ( path . node . name ) && path . node . name !== scopeLocals . get ( path . node . name ) ) {
435
- // this identifier has different names in hbs vs js, so we need to
436
- // replace the hbs name in the template compiler output with the js
437
- // name
438
- path . replaceWith ( babel . types . identifier ( scopeLocals . get ( path . node . name ) ) ) ;
439
- }
440
- // this is where we tell babel's scope system about the new reference we
441
- // just introduced. @babel /plugin-transform-typescript in particular
442
- // cares a lot about those references being present.
443
- path . scope . getBinding ( path . node . name ) ?. reference ( path ) ;
444
- } ,
430
+ target . traverse ( {
431
+ Identifier ( path : NodePath < t . Identifier > ) {
432
+ if ( scopeLocals . has ( path . node . name ) && path . node . name !== scopeLocals . get ( path . node . name ) ) {
433
+ // this identifier has different names in hbs vs js, so we need to
434
+ // replace the hbs name in the template compiler output with the js
435
+ // name
436
+ path . replaceWith ( babel . types . identifier ( scopeLocals . get ( path . node . name ) ) ) ;
437
+ }
438
+ // this is where we tell babel's scope system about the new reference we
439
+ // just introduced. @babel /plugin-transform-typescript in particular
440
+ // cares a lot about those references being present.
441
+ path . scope . getBinding ( path . node . name ) ?. reference ( path ) ;
445
442
} ,
446
- target . scope ,
447
- { } ,
448
- target . parentPath ?? undefined
449
- ) ;
443
+ } ) ;
450
444
}
451
445
452
446
function insertCompiledTemplate < EnvSpecificOptions > (
@@ -482,13 +476,6 @@ function insertCompiledTemplate<EnvSpecificOptions>(
482
476
return ;
483
477
}
484
478
} else {
485
- // The emitted `scope: () => []` here could potentially be wrong,
486
- // as it does not know about the values in JS Scope.
487
- // the scope that we pass to precompile tells the compiler what to expect will be
488
- // in scope at runtime.
489
- // but when we emit the final scope array, we need to make sure we map back to
490
- // the assignments / renames in the scope-bag from the pre-wirenformat
491
- // (which can be seen in target.toString())
492
479
precompileResultString = opts . compiler . precompile ( template , options ) ;
493
480
}
494
481
@@ -500,8 +487,6 @@ function insertCompiledTemplate<EnvSpecificOptions>(
500
487
let templateExpression = ( precompileResultAST . program . body [ 0 ] as t . VariableDeclaration )
501
488
. declarations [ 0 ] . init as t . Expression ;
502
489
503
- updateGlimmerScopeWithBabelScope ( babel , templateExpression , scopeLocals ) ;
504
-
505
490
t . addComment (
506
491
templateExpression ,
507
492
'leading' ,
@@ -674,43 +659,6 @@ function buildScope(babel: typeof Babel, locals: ScopeLocals) {
674
659
) ;
675
660
}
676
661
677
- // templateExpression.properties[]:
678
- // [0]: key.value = id
679
- // [1]: key.value = block
680
- // [2]: key.value = moduleName
681
- // [3]: key.value = scope <-- this is what needs updating
682
- // [4]: key.value = isStrictMode
683
- function updateGlimmerScopeWithBabelScope (
684
- babel : typeof Babel ,
685
- templateExpression : t . Expression ,
686
- scopeLocals : ScopeLocals
687
- ) {
688
- let t = babel . types ;
689
-
690
- if ( t . isObjectExpression ( templateExpression ) ) {
691
- let scopeObjectProperty = templateExpression . properties . find ( ( property ) => {
692
- if ( t . isObjectProperty ( property ) ) {
693
- return t . isStringLiteral ( property . key ) && property . key . value === 'scope' ;
694
- }
695
- return false ;
696
- } ) ;
697
-
698
- if ( t . isObjectProperty ( scopeObjectProperty ) ) {
699
- let scopeValue = scopeObjectProperty . value ;
700
-
701
- if ( t . isArrowFunctionExpression ( scopeValue ) ) {
702
- if ( t . isArrayExpression ( scopeValue . body ) ) {
703
- scopeValue . body . elements . map ( ( element ) => {
704
- if ( t . isIdentifier ( element ) ) {
705
- element . name = scopeLocals . get ( element . name ) ;
706
- }
707
- } ) ;
708
- }
709
- }
710
- }
711
- }
712
- }
713
-
714
662
// this is responsible both for adjusting the AST for our scope argument *and*
715
663
// ensuring that babel's scope system will see that these new identifiers
716
664
// reference their bindings. @babel /plugin-transform-typescript in particular
0 commit comments