Skip to content

Commit abd2558

Browse files
committed
chore: revert some compat code introduced by #81
1 parent 3004b5c commit abd2558

File tree

2 files changed

+23
-68
lines changed

2 files changed

+23
-68
lines changed

packages/vite/src/node/plugins/importAnalysis.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,7 @@ export function transformCjsImport(
10051005
node.type === 'ImportDeclaration' ||
10061006
node.type === 'ExportNamedDeclaration'
10071007
) {
1008-
// NOTE: node.specifiers can be null in OXC: https://github.com/oxc-project/oxc/issues/2854#issuecomment-2595115817
1009-
if (!node.specifiers?.length) {
1008+
if (!node.specifiers.length) {
10101009
return `import "${url}"`
10111010
}
10121011

packages/vite/src/node/ssr/ssrTransform.ts

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,19 @@ async function ssrTransformScript(
211211

212212
// 1. check all import statements and record id -> importName map
213213
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 ?? []
216214
// import foo from 'foo' --> foo -> __import_foo__.default
217215
// import { baz } from 'foo' --> baz -> __import_foo__.baz
218216
// import * as ok from 'foo' --> ok -> __import_foo__
219217
const importId = defineImport(hoistIndex, node, {
220-
importedNames: specifiers
218+
importedNames: node.specifiers
221219
.map((s) => {
222220
if (s.type === 'ImportSpecifier')
223221
return getIdentifierNameOrLiteralValue(s.imported) as string
224222
else if (s.type === 'ImportDefaultSpecifier') return 'default'
225223
})
226224
.filter(isDefined),
227225
})
228-
for (const spec of specifiers) {
226+
for (const spec of node.specifiers) {
229227
if (spec.type === 'ImportSpecifier') {
230228
if (spec.imported.type === 'Identifier') {
231229
idToImportMap.set(
@@ -368,9 +366,6 @@ async function ssrTransformScript(
368366
stmt.type !== 'FunctionDeclaration' &&
369367
stmt.type !== 'ClassDeclaration' &&
370368
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' &&
374369
stmt.type !== 'ImportDeclaration'
375370
) {
376371
s.appendLeft(stmt.end, ';')
@@ -537,7 +532,7 @@ function walk(
537532
}
538533

539534
;(eswalk as any)(root, {
540-
enter(node: Node, parent: Node | null, prop: string) {
535+
enter(node: Node, parent: Node | null) {
541536
if (node.type === 'ImportDeclaration') {
542537
return this.skip()
543538
}
@@ -549,10 +544,6 @@ function walk(
549544
node.type === 'StaticBlock'
550545
) {
551546
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)
556547
} else if (node.type === 'SwitchCase') {
557548
onStatements(node.consequent as Node[])
558549
}
@@ -580,7 +571,7 @@ function walk(
580571
if (node.type === 'Identifier') {
581572
if (
582573
!isInScope(node.name, parentStack) &&
583-
isRefIdentifier(node, parent!, parentStack, prop)
574+
isRefIdentifier(node, parent!, parentStack)
584575
) {
585576
// record the identifier, for DFS -> BFS
586577
identifiers.push([node, parentStack.slice(0)])
@@ -601,14 +592,13 @@ function walk(
601592
}
602593
// walk function expressions and add its arguments to known identifiers
603594
// 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) => {
606596
if (p.type === 'ObjectPattern' || p.type === 'ArrayPattern') {
607597
handlePattern(p, node)
608598
return
609599
}
610600
;(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) {
612602
// skip params default value of destructure
613603
if (
614604
parent?.type === 'AssignmentPattern' &&
@@ -618,7 +608,7 @@ function walk(
618608
}
619609
if (child.type !== 'Identifier') return
620610
// do not record as scope variable if is a destructuring keyword
621-
if (isStaticPropertyKey(child, parent, prop)) return
611+
if (isStaticPropertyKey(child, parent)) return
622612
// do not record if this is a default value
623613
// assignment of a destructuring variable
624614
if (
@@ -641,14 +631,9 @@ function walk(
641631
} else if (node.type === 'ClassExpression' && node.id) {
642632
// A class expression name could shadow an import, so add its name to the scope
643633
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') {
650635
// mark property in destructuring pattern
651-
setIsNodeInPattern(node as Property)
636+
setIsNodeInPattern(node)
652637
} else if (node.type === 'VariableDeclarator') {
653638
const parentFunction = findParentScope(
654639
parentStack,
@@ -658,9 +643,7 @@ function walk(
658643
handlePattern(node.id, parentFunction)
659644
}
660645
} 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)
664647
}
665648
},
666649

@@ -686,17 +669,10 @@ function walk(
686669
})
687670
}
688671

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[]) {
695673
// declaration id
696674
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' ||
700676
((parent.type === 'VariableDeclarator' ||
701677
parent.type === 'ClassDeclaration') &&
702678
parent.id === id)
@@ -721,7 +697,7 @@ function isRefIdentifier(
721697
}
722698

723699
// property key
724-
if (isStaticPropertyKey(id, parent, prop)) {
700+
if (isStaticPropertyKey(id, parent)) {
725701
return false
726702
}
727703

@@ -740,10 +716,9 @@ function isRefIdentifier(
740716

741717
// member expression property
742718
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
747722
) {
748723
return false
749724
}
@@ -766,30 +741,17 @@ function isRefIdentifier(
766741
}
767742

768743
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
783748

784749
const functionNodeTypeRE = /Function(?:Expression|Declaration)$|Method$/
785750
function isFunction(node: _Node): node is FunctionNode {
786751
return functionNodeTypeRE.test(node.type)
787752
}
788753

789-
// NOTE: OXC uses `FunctionBody` instead of `BlockStatement`
790-
// https://github.com/oxc-project/oxc/issues/2854
791-
const blockNodeTypeRE =
792-
/^BlockStatement$|^For(?:In|Of)?Statement$|^FunctionBody$/
754+
const blockNodeTypeRE = /^BlockStatement$|^For(?:In|Of)?Statement$/
793755
function isBlock(node: _Node) {
794756
return blockNodeTypeRE.test(node.type)
795757
}
@@ -805,13 +767,7 @@ function isInDestructuringAssignment(
805767
parent: _Node,
806768
parentStack: _Node[],
807769
): 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') {
815771
return parentStack.some((i) => i.type === 'AssignmentExpression')
816772
}
817773
return false

0 commit comments

Comments
 (0)