@@ -211,21 +211,19 @@ async function ssrTransformScript(
211
211
212
212
// 1. check all import statements and record id -> importName map
213
213
for ( const node of imports ) {
214
- // NOTE: node.specifiers can be null in OXC: https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
215
- const specifiers = node . specifiers ?? [ ]
216
214
// import foo from 'foo' --> foo -> __import_foo__.default
217
215
// import { baz } from 'foo' --> baz -> __import_foo__.baz
218
216
// import * as ok from 'foo' --> ok -> __import_foo__
219
217
const importId = defineImport ( hoistIndex , node , {
220
- importedNames : specifiers
218
+ importedNames : node . specifiers
221
219
. map ( ( s ) => {
222
220
if ( s . type === 'ImportSpecifier' )
223
221
return getIdentifierNameOrLiteralValue ( s . imported ) as string
224
222
else if ( s . type === 'ImportDefaultSpecifier' ) return 'default'
225
223
} )
226
224
. filter ( isDefined ) ,
227
225
} )
228
- for ( const spec of specifiers ) {
226
+ for ( const spec of node . specifiers ) {
229
227
if ( spec . type === 'ImportSpecifier' ) {
230
228
if ( spec . imported . type === 'Identifier' ) {
231
229
idToImportMap . set (
@@ -368,9 +366,6 @@ async function ssrTransformScript(
368
366
stmt . type !== 'FunctionDeclaration' &&
369
367
stmt . type !== 'ClassDeclaration' &&
370
368
stmt . type !== 'BlockStatement' &&
371
- // NOTE: OXC uses `FunctionBody` instead of `BlockStatement`
372
- // https://github.com/oxc-project/oxc/issues/2854
373
- ( stmt . type as any ) !== 'FunctionBody' &&
374
369
stmt . type !== 'ImportDeclaration'
375
370
) {
376
371
s . appendLeft ( stmt . end , ';' )
@@ -537,7 +532,7 @@ function walk(
537
532
}
538
533
539
534
; ( eswalk as any ) ( root , {
540
- enter ( node : Node , parent : Node | null , prop : string ) {
535
+ enter ( node : Node , parent : Node | null ) {
541
536
if ( node . type === 'ImportDeclaration' ) {
542
537
return this . skip ( )
543
538
}
@@ -549,10 +544,6 @@ function walk(
549
544
node . type === 'StaticBlock'
550
545
) {
551
546
onStatements ( node . body as Node [ ] )
552
- // NOTE: OXC uses `FunctionBody` instead of `BlockStatement`
553
- // https://github.com/oxc-project/oxc/issues/2854
554
- } else if ( ( node . type as any ) === 'FunctionBody' ) {
555
- onStatements ( ( node as any ) . statements )
556
547
} else if ( node . type === 'SwitchCase' ) {
557
548
onStatements ( node . consequent as Node [ ] )
558
549
}
@@ -580,7 +571,7 @@ function walk(
580
571
if ( node . type === 'Identifier' ) {
581
572
if (
582
573
! isInScope ( node . name , parentStack ) &&
583
- isRefIdentifier ( node , parent ! , parentStack , prop )
574
+ isRefIdentifier ( node , parent ! , parentStack )
584
575
) {
585
576
// record the identifier, for DFS -> BFS
586
577
identifiers . push ( [ node , parentStack . slice ( 0 ) ] )
@@ -601,14 +592,13 @@ function walk(
601
592
}
602
593
// walk function expressions and add its arguments to known identifiers
603
594
// so that we don't prefix them
604
- // NOTE: `node.params.items` is used for OXC instead of `node.params`: https://github.com/oxc-project/oxc/issues/2854
605
- ; ( node . params as any ) . items . forEach ( ( p : Node ) => {
595
+ node . params . forEach ( ( p ) => {
606
596
if ( p . type === 'ObjectPattern' || p . type === 'ArrayPattern' ) {
607
597
handlePattern ( p , node )
608
598
return
609
599
}
610
600
; ( eswalk as any ) ( p . type === 'AssignmentPattern' ? p . left : p , {
611
- enter ( child : Node , parent : Node | undefined , prop : string ) {
601
+ enter ( child : Node , parent : Node | undefined ) {
612
602
// skip params default value of destructure
613
603
if (
614
604
parent ?. type === 'AssignmentPattern' &&
@@ -618,7 +608,7 @@ function walk(
618
608
}
619
609
if ( child . type !== 'Identifier' ) return
620
610
// do not record as scope variable if is a destructuring keyword
621
- if ( isStaticPropertyKey ( child , parent , prop ) ) return
611
+ if ( isStaticPropertyKey ( child , parent ) ) return
622
612
// do not record if this is a default value
623
613
// assignment of a destructuring variable
624
614
if (
@@ -641,14 +631,9 @@ function walk(
641
631
} else if ( node . type === 'ClassExpression' && node . id ) {
642
632
// A class expression name could shadow an import, so add its name to the scope
643
633
setScope ( node , node . id . name )
644
- } else if (
645
- // NOTE: OXC uses `BindingProperty` instead of `Property`
646
- // https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
647
- ( node . type as any ) === 'BindingProperty' &&
648
- parent ! . type === 'ObjectPattern'
649
- ) {
634
+ } else if ( node . type === 'Property' && parent ! . type === 'ObjectPattern' ) {
650
635
// mark property in destructuring pattern
651
- setIsNodeInPattern ( node as Property )
636
+ setIsNodeInPattern ( node )
652
637
} else if ( node . type === 'VariableDeclarator' ) {
653
638
const parentFunction = findParentScope (
654
639
parentStack ,
@@ -658,9 +643,7 @@ function walk(
658
643
handlePattern ( node . id , parentFunction )
659
644
}
660
645
} else if ( node . type === 'CatchClause' && node . param ) {
661
- // NOTE: OXC has CatchParameter inside CatchClause
662
- // https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
663
- handlePattern ( ( node . param as any ) . pattern , node )
646
+ handlePattern ( node . param , node )
664
647
}
665
648
} ,
666
649
@@ -686,17 +669,10 @@ function walk(
686
669
} )
687
670
}
688
671
689
- function isRefIdentifier (
690
- id : Identifier ,
691
- parent : _Node ,
692
- parentStack : _Node [ ] ,
693
- prop : string ,
694
- ) {
672
+ function isRefIdentifier ( id : Identifier , parent : _Node , parentStack : _Node [ ] ) {
695
673
// declaration id
696
674
if (
697
- // NOTE: OXC has CatchParameter inside CatchClause
698
- // https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
699
- ( parent . type as any ) === 'CatchParameter' ||
675
+ parent . type === 'CatchClause' ||
700
676
( ( parent . type === 'VariableDeclarator' ||
701
677
parent . type === 'ClassDeclaration' ) &&
702
678
parent . id === id )
@@ -721,7 +697,7 @@ function isRefIdentifier(
721
697
}
722
698
723
699
// property key
724
- if ( isStaticPropertyKey ( id , parent , prop ) ) {
700
+ if ( isStaticPropertyKey ( id , parent ) ) {
725
701
return false
726
702
}
727
703
@@ -740,10 +716,9 @@ function isRefIdentifier(
740
716
741
717
// member expression property
742
718
if (
743
- // NOTE: OXC uses StaticMemberExpression instead of MemberExpression + `computed: false`
744
- // https://github.com/oxc-project/oxc/issues/2854
745
- ( parent . type as any ) === 'StaticMemberExpression' &&
746
- ( parent as any ) . property === id
719
+ parent . type === 'MemberExpression' &&
720
+ parent . property === id &&
721
+ ! parent . computed
747
722
) {
748
723
return false
749
724
}
@@ -766,30 +741,17 @@ function isRefIdentifier(
766
741
}
767
742
768
743
const isStaticProperty = ( node : _Node ) : node is Property =>
769
- // NOTE: OXC uses `ObjectProperty` instead of `Property`
770
- // https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
771
- ( ( node . type as any ) === 'ObjectProperty' ||
772
- ( node . type as any ) === 'BindingProperty' ) &&
773
- ! ( node as Property ) . computed
774
-
775
- const isStaticPropertyKey = (
776
- node : _Node ,
777
- parent : _Node | undefined ,
778
- prop : string ,
779
- ) =>
780
- // NOTE: probably OXC has a similar problem with handling references here
781
- // https://github.com/vitejs/vite/pull/14508#discussion_r1341972441
782
- parent && isStaticProperty ( parent ) && prop === 'key' && parent . key === node
744
+ node . type === 'Property' && ! node . computed
745
+
746
+ const isStaticPropertyKey = ( node : _Node , parent : _Node | undefined ) =>
747
+ parent && isStaticProperty ( parent ) && parent . key === node
783
748
784
749
const functionNodeTypeRE = / F u n c t i o n (?: E x p r e s s i o n | D e c l a r a t i o n ) $ | M e t h o d $ /
785
750
function isFunction ( node : _Node ) : node is FunctionNode {
786
751
return functionNodeTypeRE . test ( node . type )
787
752
}
788
753
789
- // NOTE: OXC uses `FunctionBody` instead of `BlockStatement`
790
- // https://github.com/oxc-project/oxc/issues/2854
791
- const blockNodeTypeRE =
792
- / ^ B l o c k S t a t e m e n t $ | ^ F o r (?: I n | O f ) ? S t a t e m e n t $ | ^ F u n c t i o n B o d y $ /
754
+ const blockNodeTypeRE = / ^ B l o c k S t a t e m e n t $ | ^ F o r (?: I n | O f ) ? S t a t e m e n t $ /
793
755
function isBlock ( node : _Node ) {
794
756
return blockNodeTypeRE . test ( node . type )
795
757
}
@@ -805,13 +767,7 @@ function isInDestructuringAssignment(
805
767
parent : _Node ,
806
768
parentStack : _Node [ ] ,
807
769
) : boolean {
808
- // NOTE: OXC uses `ObjectProperty` instead of `Property`
809
- // https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
810
- if (
811
- ( parent . type as any ) === 'ObjectProperty' ||
812
- ( parent . type as any ) === 'BindingProperty' ||
813
- parent . type === 'ArrayPattern'
814
- ) {
770
+ if ( parent . type === 'Property' || parent . type === 'ArrayPattern' ) {
815
771
return parentStack . some ( ( i ) => i . type === 'AssignmentExpression' )
816
772
}
817
773
return false
0 commit comments