mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
chore: migrate to oxc-walker
This commit is contained in:
parent
440875b486
commit
2fd904d623
@ -81,7 +81,6 @@
|
|||||||
"errx": "^0.1.0",
|
"errx": "^0.1.0",
|
||||||
"esbuild": "^0.24.0",
|
"esbuild": "^0.24.0",
|
||||||
"escape-string-regexp": "^5.0.0",
|
"escape-string-regexp": "^5.0.0",
|
||||||
"estree-walker": "^3.0.3",
|
|
||||||
"globby": "^14.0.2",
|
"globby": "^14.0.2",
|
||||||
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
||||||
"hookable": "^5.5.3",
|
"hookable": "^5.5.3",
|
||||||
@ -99,6 +98,7 @@
|
|||||||
"ofetch": "^1.4.1",
|
"ofetch": "^1.4.1",
|
||||||
"ohash": "^1.1.4",
|
"ohash": "^1.1.4",
|
||||||
"oxc-parser": "^0.38.0",
|
"oxc-parser": "^0.38.0",
|
||||||
|
"oxc-walker": "^0.0.1",
|
||||||
"pathe": "^1.1.2",
|
"pathe": "^1.1.2",
|
||||||
"perfect-debounce": "^1.0.0",
|
"perfect-debounce": "^1.0.0",
|
||||||
"pkg-types": "^1.2.1",
|
"pkg-types": "^1.2.1",
|
||||||
@ -127,7 +127,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxt/scripts": "0.9.5",
|
"@nuxt/scripts": "0.9.5",
|
||||||
"@parcel/watcher": "2.5.0",
|
"@parcel/watcher": "2.5.0",
|
||||||
"@types/estree": "1.0.6",
|
|
||||||
"@vitejs/plugin-vue": "5.2.1",
|
"@vitejs/plugin-vue": "5.2.1",
|
||||||
"@vue/compiler-sfc": "3.5.13",
|
"@vue/compiler-sfc": "3.5.13",
|
||||||
"unbuild": "3.0.0-rc.11",
|
"unbuild": "3.0.0-rc.11",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
import type { Component } from 'nuxt/schema'
|
import type { Component } from 'nuxt/schema'
|
||||||
import { parseAndWalk, withLocations } from '../../core/utils/parse'
|
import { parseAndWalk } from 'oxc-walker'
|
||||||
|
|
||||||
import { SX_RE, isVue } from '../../core/utils'
|
import { SX_RE, isVue } from '../../core/utils'
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { start, end } = withLocations(node.declaration)
|
const { start, end } = node.declaration
|
||||||
s.overwrite(start, end, `Object.assign(${code.slice(start, end)}, { __name: ${JSON.stringify(component.pascalName)} })`)
|
s.overwrite(start, end, `Object.assign(${code.slice(start, end)}, { __name: ${JSON.stringify(component.pascalName)} })`)
|
||||||
this.skip()
|
this.skip()
|
||||||
})
|
})
|
||||||
|
@ -5,9 +5,9 @@ import type { BindingPattern, BindingProperty, BindingRestElement, CallExpressio
|
|||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import type { Component } from '@nuxt/schema'
|
import type { Component } from '@nuxt/schema'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
|
import { parseAndWalk, walk } from 'oxc-walker'
|
||||||
|
import type { Node } from 'oxc-walker'
|
||||||
|
|
||||||
import { parseAndWalk, walk } from '../../core/utils/parse'
|
|
||||||
import type { Node } from '../../core/utils/parse'
|
|
||||||
import { distDir } from '../../dirs'
|
import { distDir } from '../../dirs'
|
||||||
|
|
||||||
interface TreeShakeTemplatePluginOptions {
|
interface TreeShakeTemplatePluginOptions {
|
||||||
|
@ -7,9 +7,9 @@ import { parseQuery, parseURL } from 'ufo'
|
|||||||
import escapeRE from 'escape-string-regexp'
|
import escapeRE from 'escape-string-regexp'
|
||||||
import { findStaticImports, parseStaticImport } from 'mlly'
|
import { findStaticImports, parseStaticImport } from 'mlly'
|
||||||
import type { BindingPattern } from 'oxc-parser'
|
import type { BindingPattern } from 'oxc-parser'
|
||||||
|
import { parseAndWalk, walk } from 'oxc-walker'
|
||||||
|
|
||||||
import { matchWithStringOrRegex } from '../utils/plugins'
|
import { matchWithStringOrRegex } from '../utils/plugins'
|
||||||
import { parseAndWalk, walk } from '../utils/parse'
|
|
||||||
|
|
||||||
interface ComposableKeysOptions {
|
interface ComposableKeysOptions {
|
||||||
sourcemap: boolean
|
sourcemap: boolean
|
||||||
|
@ -6,8 +6,7 @@ import { createUnplugin } from 'unplugin'
|
|||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
import { normalize } from 'pathe'
|
import { normalize } from 'pathe'
|
||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
|
import { parseAndWalk } from 'oxc-walker'
|
||||||
import { parseAndWalk } from '../../core/utils/parse'
|
|
||||||
|
|
||||||
import type { ObjectPlugin, PluginMeta } from '#app'
|
import type { ObjectPlugin, PluginMeta } from '#app'
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ import { transform } from 'esbuild'
|
|||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
import { hash } from 'ohash'
|
import { hash } from 'ohash'
|
||||||
|
import { parseAndWalk } from 'oxc-walker'
|
||||||
|
|
||||||
import { parseAndWalk } from '../../core/utils/parse'
|
|
||||||
import { isJS, isVue } from '../utils'
|
import { isJS, isVue } from '../utils'
|
||||||
|
|
||||||
export function PrehydrateTransformPlugin (options: { sourcemap?: boolean } = {}) {
|
export function PrehydrateTransformPlugin (options: { sourcemap?: boolean } = {}) {
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import { parseSync } from 'oxc-parser'
|
|
||||||
import type { CatchClause, ClassBody, Declaration, Expression, MethodDefinition, ModuleDeclaration, ObjectProperty, Pattern, PrivateIdentifier, Program, PropertyDefinition, SpreadElement, Statement, Super, SwitchCase, TemplateElement } from 'oxc-parser'
|
|
||||||
import { walk as _walk } from 'estree-walker'
|
|
||||||
import type { SyncHandler } from 'estree-walker'
|
|
||||||
import type { Node as ESTreeNode, Program as ESTreeProgram, ModuleSpecifier } from 'estree'
|
|
||||||
|
|
||||||
/** estree also has AssignmentProperty, Identifier and Literal as possible node types */
|
|
||||||
export type Node = Declaration | Expression | ClassBody | CatchClause | MethodDefinition | ModuleDeclaration | ModuleSpecifier | Pattern | PrivateIdentifier | Program | SpreadElement | Statement | Super | SwitchCase | TemplateElement | ObjectProperty | PropertyDefinition
|
|
||||||
|
|
||||||
type WalkerCallback = (this: ThisParameterType<SyncHandler>, node: Node, parent: Node | null, ctx: { key: string | number | symbol | null | undefined, index: number | null | undefined, ast: Program | Node }) => void
|
|
||||||
|
|
||||||
export function walk (ast: Program | Node, callback: { enter?: WalkerCallback, leave?: WalkerCallback }) {
|
|
||||||
return _walk(ast as unknown as ESTreeProgram | ESTreeNode, {
|
|
||||||
enter (node, parent, key, index) {
|
|
||||||
callback.enter?.call(this, node as Node, parent as Node | null, { key, index, ast })
|
|
||||||
},
|
|
||||||
leave (node, parent, key, index) {
|
|
||||||
callback.leave?.call(this, node as Node, parent as Node | null, { key, index, ast })
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseAndWalk (code: string, sourceFilename: string, callback: WalkerCallback): Program
|
|
||||||
export function parseAndWalk (code: string, sourceFilename: string, object: { enter?: WalkerCallback, leave?: WalkerCallback }): Program
|
|
||||||
export function parseAndWalk (code: string, sourceFilename: string, callback: { enter?: WalkerCallback, leave?: WalkerCallback } | WalkerCallback) {
|
|
||||||
const ast = parseSync(code, { sourceType: 'module', sourceFilename }).program
|
|
||||||
walk(ast, typeof callback === 'function' ? { enter: callback } : callback)
|
|
||||||
return ast
|
|
||||||
}
|
|
||||||
|
|
||||||
type WithLocations<T> = T & { start: number, end: number }
|
|
||||||
|
|
||||||
export function withLocations<T> (node: T): WithLocations<T> {
|
|
||||||
return node as WithLocations<T>
|
|
||||||
}
|
|
@ -6,8 +6,7 @@ import { findExports, findStaticImports, parseStaticImport } from 'mlly'
|
|||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
import { isAbsolute } from 'pathe'
|
import { isAbsolute } from 'pathe'
|
||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
|
import { parseAndWalk, walk } from 'oxc-walker'
|
||||||
import { parseAndWalk, walk } from '../../core/utils/parse'
|
|
||||||
|
|
||||||
interface PageMetaPluginOptions {
|
interface PageMetaPluginOptions {
|
||||||
dev?: boolean
|
dev?: boolean
|
||||||
|
@ -2,9 +2,9 @@ import { runInNewContext } from 'node:vm'
|
|||||||
import type { NuxtPage } from '@nuxt/schema'
|
import type { NuxtPage } from '@nuxt/schema'
|
||||||
import type { NitroRouteConfig } from 'nitro/types'
|
import type { NitroRouteConfig } from 'nitro/types'
|
||||||
import { normalize } from 'pathe'
|
import { normalize } from 'pathe'
|
||||||
|
import { parseAndWalk } from 'oxc-walker'
|
||||||
|
|
||||||
import { getLoader } from '../core/utils'
|
import { getLoader } from '../core/utils'
|
||||||
import { parseAndWalk } from '../core/utils/parse'
|
|
||||||
import { extractScriptContent, pathToNitroGlob } from './utils'
|
import { extractScriptContent, pathToNitroGlob } from './utils'
|
||||||
|
|
||||||
const ROUTE_RULE_RE = /\bdefineRouteRules\(/
|
const ROUTE_RULE_RE = /\bdefineRouteRules\(/
|
||||||
|
@ -9,8 +9,8 @@ import { filename } from 'pathe/utils'
|
|||||||
import { hash } from 'ohash'
|
import { hash } from 'ohash'
|
||||||
import type { ObjectProperty } from 'oxc-parser'
|
import type { ObjectProperty } from 'oxc-parser'
|
||||||
import type { NuxtPage } from 'nuxt/schema'
|
import type { NuxtPage } from 'nuxt/schema'
|
||||||
|
import { parseAndWalk } from 'oxc-walker'
|
||||||
|
|
||||||
import { parseAndWalk } from '../core/utils/parse'
|
|
||||||
import { getLoader, uniqueBy } from '../core/utils'
|
import { getLoader, uniqueBy } from '../core/utils'
|
||||||
import { toArray } from '../utils'
|
import { toArray } from '../utils'
|
||||||
|
|
||||||
|
@ -338,9 +338,6 @@ importers:
|
|||||||
escape-string-regexp:
|
escape-string-regexp:
|
||||||
specifier: ^5.0.0
|
specifier: ^5.0.0
|
||||||
version: 5.0.0
|
version: 5.0.0
|
||||||
estree-walker:
|
|
||||||
specifier: ^3.0.3
|
|
||||||
version: 3.0.3
|
|
||||||
globby:
|
globby:
|
||||||
specifier: ^14.0.2
|
specifier: ^14.0.2
|
||||||
version: 14.0.2
|
version: 14.0.2
|
||||||
@ -392,6 +389,9 @@ importers:
|
|||||||
oxc-parser:
|
oxc-parser:
|
||||||
specifier: ^0.38.0
|
specifier: ^0.38.0
|
||||||
version: 0.38.0
|
version: 0.38.0
|
||||||
|
oxc-walker:
|
||||||
|
specifier: ^0.0.1
|
||||||
|
version: 0.0.1
|
||||||
pathe:
|
pathe:
|
||||||
specifier: ^1.1.2
|
specifier: ^1.1.2
|
||||||
version: 1.1.2
|
version: 1.1.2
|
||||||
@ -471,9 +471,6 @@ importers:
|
|||||||
'@parcel/watcher':
|
'@parcel/watcher':
|
||||||
specifier: 2.5.0
|
specifier: 2.5.0
|
||||||
version: 2.5.0
|
version: 2.5.0
|
||||||
'@types/estree':
|
|
||||||
specifier: 1.0.6
|
|
||||||
version: 1.0.6
|
|
||||||
'@vitejs/plugin-vue':
|
'@vitejs/plugin-vue':
|
||||||
specifier: 5.2.1
|
specifier: 5.2.1
|
||||||
version: 5.2.1(vite@6.0.1(@types/node@22.10.1)(jiti@2.4.0)(sass@1.78.0)(terser@5.32.0)(tsx@4.19.1)(yaml@2.5.1))(vue@3.5.13(typescript@5.6.3))
|
version: 5.2.1(vite@6.0.1(@types/node@22.10.1)(jiti@2.4.0)(sass@1.78.0)(terser@5.32.0)(tsx@4.19.1)(yaml@2.5.1))(vue@3.5.13(typescript@5.6.3))
|
||||||
@ -5961,6 +5958,9 @@ packages:
|
|||||||
oxc-parser@0.38.0:
|
oxc-parser@0.38.0:
|
||||||
resolution: {integrity: sha512-w/cUL64wDb72gaBoOnvodKgHhNF9pDjb2b8gPkDKJDTvIvlbcE9XGDT3cnXOP4N3XCMrRT4MC23bCHGb3gCFSQ==}
|
resolution: {integrity: sha512-w/cUL64wDb72gaBoOnvodKgHhNF9pDjb2b8gPkDKJDTvIvlbcE9XGDT3cnXOP4N3XCMrRT4MC23bCHGb3gCFSQ==}
|
||||||
|
|
||||||
|
oxc-walker@0.0.1:
|
||||||
|
resolution: {integrity: sha512-lb1iCUTl2qy/ZYk1+lC8nxUBzCpcsupofSFqwHlP3GtbE/2uLq2A0Q448fDs9LDIuh+syC6sebonI0qpjh2Opw==}
|
||||||
|
|
||||||
p-limit@2.3.0:
|
p-limit@2.3.0:
|
||||||
resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==}
|
resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@ -13667,6 +13667,12 @@ snapshots:
|
|||||||
'@oxc-parser/binding-win32-arm64-msvc': 0.38.0
|
'@oxc-parser/binding-win32-arm64-msvc': 0.38.0
|
||||||
'@oxc-parser/binding-win32-x64-msvc': 0.38.0
|
'@oxc-parser/binding-win32-x64-msvc': 0.38.0
|
||||||
|
|
||||||
|
oxc-walker@0.0.1:
|
||||||
|
dependencies:
|
||||||
|
'@types/estree': 1.0.6
|
||||||
|
estree-walker: 3.0.3
|
||||||
|
oxc-parser: 0.38.0
|
||||||
|
|
||||||
p-limit@2.3.0:
|
p-limit@2.3.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
p-try: 2.2.0
|
p-try: 2.2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user