diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json index f2b352869..0c660a314 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -64,7 +64,7 @@ "dependencies": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", - "estree-walker": "^2.0.2", + "estree-walker": "^3.0.3", "fdir": "^6.2.0", "is-reference": "1.2.1", "magic-string": "^0.30.3", diff --git a/packages/commonjs/test/fixtures/samples/caching/rollupWorker.js b/packages/commonjs/test/fixtures/samples/caching/rollupWorker.js index eb7e39ea6..ec0084819 100644 --- a/packages/commonjs/test/fixtures/samples/caching/rollupWorker.js +++ b/packages/commonjs/test/fixtures/samples/caching/rollupWorker.js @@ -2,12 +2,11 @@ const { workerData, parentPort } = require('worker_threads'); const { rollup } = require('rollup'); -const commonjs = require('../../../..'); -const { getCodeFromBundle } = require('../../../helpers/util'); - generateCode(workerData); async function generateCode(cache) { + const commonjs = (await import('current-package')).default; + const { getCodeFromBundle } = await import('../../../helpers/util.mjs'); const code = await getCodeFromBundle( await rollup({ input: 'fixtures/samples/caching/main.js', diff --git a/packages/commonjs/test/form.js b/packages/commonjs/test/form.mjs similarity index 90% rename from packages/commonjs/test/form.js rename to packages/commonjs/test/form.mjs index ba1534370..ea23210d0 100644 --- a/packages/commonjs/test/form.js +++ b/packages/commonjs/test/form.mjs @@ -1,14 +1,18 @@ /* eslint-disable global-require, import/no-dynamic-require, no-console */ -const fs = require('fs'); -const path = require('path'); +import * as fs from 'fs'; +import { createRequire } from 'module'; +import * as path from 'path'; +import { fileURLToPath } from 'url'; -const acorn = require('acorn'); -const test = require('ava'); +import * as acorn from 'acorn'; +import test from 'ava'; -const { commonjs } = require('./helpers/util.js'); +import { commonjs } from './helpers/util.mjs'; -process.chdir(__dirname); +const require = createRequire(import.meta.url); + +process.chdir(fileURLToPath(new URL('.', import.meta.url))); const transformContext = { error: (base, props) => { diff --git a/packages/commonjs/test/function.js b/packages/commonjs/test/function.mjs similarity index 79% rename from packages/commonjs/test/function.js rename to packages/commonjs/test/function.mjs index b8701ef74..a71fca11a 100644 --- a/packages/commonjs/test/function.js +++ b/packages/commonjs/test/function.mjs @@ -1,13 +1,17 @@ /* eslint-disable global-require, import/no-dynamic-require, no-console */ -const { readdirSync } = require('fs'); +import { readdirSync } from 'fs'; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; -const test = require('ava'); -const { rollup } = require('rollup'); +import test from 'ava'; +import { rollup } from 'rollup'; -const { commonjs, getCodeMapFromBundle, runCodeSplitTest } = require('./helpers/util'); +import { commonjs, getCodeMapFromBundle, runCodeSplitTest } from './helpers/util.mjs'; -process.chdir(__dirname); +const require = createRequire(import.meta.url); + +process.chdir(fileURLToPath(new URL('.', import.meta.url))); readdirSync('./fixtures/function').forEach((dir) => { let config; diff --git a/packages/commonjs/test/helpers/util.js b/packages/commonjs/test/helpers/util.mjs similarity index 77% rename from packages/commonjs/test/helpers/util.js rename to packages/commonjs/test/helpers/util.mjs index 4d8bb2fda..cbb7ade53 100644 --- a/packages/commonjs/test/helpers/util.js +++ b/packages/commonjs/test/helpers/util.mjs @@ -1,13 +1,15 @@ -const path = require('path'); +import { createRequire } from 'module'; +import * as path from 'path'; -const commonjsPlugin = require('../..'); +import commonjsPlugin from 'current-package'; -function commonjs(options) { - delete require.cache[require.resolve('../..')]; +const require = createRequire(import.meta.url); + +export function commonjs(options) { return commonjsPlugin(options); } -function normalizePathSlashes(path) { +export function normalizePathSlashes(path) { return path.replace(/\\/g, '/'); } @@ -27,7 +29,7 @@ function requireWithContext(code, context) { return contextWithExports.module.exports; } -function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {}) { +export function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {}) { const requireFromOutputVia = (importer) => (importee) => { const outputId = path.posix.join(path.posix.dirname(importer), importee); const code = codeMap[outputId]; @@ -63,7 +65,7 @@ function runCodeSplitTest(codeMap, t, entryName = 'main.js', configContext = {}) return { exports, global }; } -async function getCodeMapFromBundle(bundle, options = {}) { +export async function getCodeMapFromBundle(bundle, options = {}) { const generated = await bundle.generate({ interop: 'compat', exports: 'auto', @@ -77,21 +79,12 @@ async function getCodeMapFromBundle(bundle, options = {}) { return codeMap; } -async function getCodeFromBundle(bundle, customOptions = {}) { +export async function getCodeFromBundle(bundle, customOptions = {}) { const options = { exports: 'auto', format: 'cjs', ...customOptions }; return (await bundle.generate(options)).output[0].code; } -async function executeBundle(bundle, t, { context, exports, testEntry = 'main.js' } = {}) { +export async function executeBundle(bundle, t, { context, exports, testEntry = 'main.js' } = {}) { const codeMap = await getCodeMapFromBundle(bundle, exports ? { exports } : {}); return runCodeSplitTest(codeMap, t, testEntry, context); } - -module.exports = { - commonjs, - executeBundle, - getCodeFromBundle, - getCodeMapFromBundle, - normalizePathSlashes, - runCodeSplitTest -}; diff --git a/packages/commonjs/test/node_modules/current-package b/packages/commonjs/test/node_modules/current-package new file mode 120000 index 000000000..6581736d6 --- /dev/null +++ b/packages/commonjs/test/node_modules/current-package @@ -0,0 +1 @@ +../../ \ No newline at end of file diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.mjs.md similarity index 99% rename from packages/commonjs/test/snapshots/function.js.md rename to packages/commonjs/test/snapshots/function.mjs.md index 758c8aa3f..69dd02297 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/function.js` +# Snapshot report for `test/function.mjs` -The actual snapshot is saved in `function.js.snap`. +The actual snapshot is saved in `function.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.mjs.snap similarity index 100% rename from packages/commonjs/test/snapshots/function.js.snap rename to packages/commonjs/test/snapshots/function.mjs.snap diff --git a/packages/commonjs/test/snapshots/test.js.md b/packages/commonjs/test/snapshots/test.mjs.md similarity index 99% rename from packages/commonjs/test/snapshots/test.js.md rename to packages/commonjs/test/snapshots/test.mjs.md index b12fd1200..4886edad6 100644 --- a/packages/commonjs/test/snapshots/test.js.md +++ b/packages/commonjs/test/snapshots/test.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/test.js` +# Snapshot report for `test/test.mjs` -The actual snapshot is saved in `test.js.snap`. +The actual snapshot is saved in `test.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/packages/commonjs/test/snapshots/test.js.snap b/packages/commonjs/test/snapshots/test.mjs.snap similarity index 100% rename from packages/commonjs/test/snapshots/test.js.snap rename to packages/commonjs/test/snapshots/test.mjs.snap diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.mjs similarity index 98% rename from packages/commonjs/test/test.js rename to packages/commonjs/test/test.mjs index 1ef56aa0d..e4bca4cf5 100644 --- a/packages/commonjs/test/test.js +++ b/packages/commonjs/test/test.mjs @@ -1,27 +1,31 @@ /* eslint-disable line-comment-position, no-new-func, no-undefined */ -const os = require('os'); -const path = require('path'); - -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const test = require('ava'); -const { getLocator } = require('locate-character'); -const { rollup } = require('rollup'); -const { install } = require('source-map-support'); - -const { testBundle } = require('../../../util/test'); - -const { peerDependencies } = require('../package.json'); - -const { +import { createRequire } from 'module'; +import * as os from 'os'; +import * as path from 'path'; +import { fileURLToPath } from 'url'; + +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import test from 'ava'; +import { getLocator } from 'locate-character'; +import { rollup } from 'rollup'; +import { install } from 'source-map-support'; + +import { commonjs, executeBundle, getCodeFromBundle, normalizePathSlashes -} = require('./helpers/util.js'); +} from './helpers/util.mjs'; + +const require = createRequire(import.meta.url); + +const { peerDependencies } = require('../package.json'); + +const { testBundle } = require('../../../util/test.js'); install(); -test.beforeEach(() => process.chdir(__dirname)); +test.beforeEach(() => process.chdir(fileURLToPath(new URL('.', import.meta.url)))); const loader = (modules) => { return { @@ -228,7 +232,7 @@ test.serial('handles symlinked node_modules with preserveSymlinks: false', (t) = // ensure we resolve starting from a directory with // symlinks in node_modules. - process.chdir(path.join(__dirname, 'fixtures/samples/symlinked-node-modules')); + process.chdir(fileURLToPath(new URL('fixtures/samples/symlinked-node-modules', import.meta.url))); return t.notThrowsAsync( rollup({ @@ -652,7 +656,7 @@ if (Number(/^v(\d+)/.exec(process.version)[1]) >= 12) { // We do a second run in a worker so that all internal state is cleared const { Worker } = await import('worker_threads'); const getRollupUpCodeWithCache = new Worker( - path.join(__dirname, 'fixtures/samples/caching/rollupWorker.js'), + fileURLToPath(new URL('fixtures/samples/caching/rollupWorker.js', import.meta.url)), { workerData: cache } diff --git a/packages/dynamic-import-vars/package.json b/packages/dynamic-import-vars/package.json index 305439fc8..66bbc3ff9 100644 --- a/packages/dynamic-import-vars/package.json +++ b/packages/dynamic-import-vars/package.json @@ -65,7 +65,7 @@ "dependencies": { "@rollup/pluginutils": "^5.0.1", "astring": "^1.8.5", - "estree-walker": "^2.0.2", + "estree-walker": "^3.0.3", "fast-glob": "^3.2.12", "magic-string": "^0.30.3" }, diff --git a/packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.js b/packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.mjs similarity index 65% rename from packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.js rename to packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.mjs index 58c40091c..dd09c6809 100644 --- a/packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.js +++ b/packages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.mjs @@ -1,13 +1,16 @@ /* eslint-disable import/no-unresolved */ -const { join } = require('path'); +import { posix } from 'path'; +import { fileURLToPath } from 'url'; -const test = require('ava'); -const { rollup } = require('rollup'); +import test from 'ava'; +import { rollup } from 'rollup'; -const dynamicImportVars = require('current-package'); +import dynamicImportVars from 'current-package'; -process.chdir(join(__dirname, 'fixtures')); +const DIRNAME = fileURLToPath(new URL('.', import.meta.url)); + +process.chdir(fileURLToPath(new URL('fixtures', import.meta.url))); test('single dir', async (t) => { const bundle = await rollup({ @@ -16,9 +19,9 @@ test('single dir', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-single-dir.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js') + posix.resolve(DIRNAME, './fixtures/fixture-single-dir.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js') ]; t.deepEqual( @@ -35,12 +38,12 @@ test('multiple dirs', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-multiple-dirs.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js'), - require.resolve('./fixtures/module-dir-b/module-b-1.js'), - require.resolve('./fixtures/module-dir-b/module-b-2.js'), - require.resolve('./fixtures/sub-dir/fixture-upwards-path.js') + posix.resolve(DIRNAME, './fixtures/fixture-multiple-dirs.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js'), + posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js') ]; t.deepEqual( @@ -57,9 +60,9 @@ test('upwards dir path', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/sub-dir/fixture-upwards-path.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js') + posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js') ]; t.deepEqual( @@ -76,11 +79,11 @@ test('complex concatenation', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-complex-concat.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js'), - require.resolve('./fixtures/module-dir-b/module-b-1.js'), - require.resolve('./fixtures/module-dir-b/module-b-2.js') + posix.resolve(DIRNAME, './fixtures/fixture-complex-concat.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js') ]; t.deepEqual( @@ -97,9 +100,9 @@ test('own directory', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-own-dir.js'), - require.resolve('./fixtures/root-module-a.js'), - require.resolve('./fixtures/root-module-b.js') + posix.resolve(DIRNAME, './fixtures/fixture-own-dir.js'), + posix.resolve(DIRNAME, './fixtures/root-module-a.js'), + posix.resolve(DIRNAME, './fixtures/root-module-b.js') ]; t.deepEqual( @@ -116,12 +119,12 @@ test('multiple dynamic imports', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-multiple-imports.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js'), - require.resolve('./fixtures/module-dir-b/module-b-1.js'), - require.resolve('./fixtures/module-dir-b/module-b-2.js'), - require.resolve('./fixtures/sub-dir/fixture-upwards-path.js') + posix.resolve(DIRNAME, './fixtures/fixture-multiple-imports.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-b/module-b-2.js'), + posix.resolve(DIRNAME, './fixtures/sub-dir/fixture-upwards-path.js') ]; t.deepEqual( @@ -138,8 +141,8 @@ test("doesn't change imports that should not be changed", async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-unchanged.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js') + posix.resolve(DIRNAME, './fixtures/fixture-unchanged.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js') ]; t.deepEqual( @@ -160,7 +163,7 @@ test('can exclude files', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); - const expectedFiles = [require.resolve('./fixtures/fixture-excluded.js')]; + const expectedFiles = [posix.resolve(DIRNAME, './fixtures/fixture-excluded.js')]; t.deepEqual( expectedFiles, @@ -193,9 +196,9 @@ test('dynamic imports assertions', async (t) => { }); const { output } = await bundle.generate({ format: 'es' }); const expectedFiles = [ - require.resolve('./fixtures/fixture-assert.js'), - require.resolve('./fixtures/module-dir-a/module-a-1.js'), - require.resolve('./fixtures/module-dir-a/module-a-2.js') + posix.resolve(DIRNAME, './fixtures/fixture-assert.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-1.js'), + posix.resolve(DIRNAME, './fixtures/module-dir-a/module-a-2.js') ]; t.deepEqual( @@ -228,7 +231,8 @@ test('throws if no files in dir when `errorWhenNoFilesFound` is set', async (t) } catch (error) { t.deepEqual( error.message, - `No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${require.resolve( + `No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${posix.resolve( + DIRNAME, './fixtures/fixture-no-files.js' )}` ); @@ -245,7 +249,8 @@ test('warns if no files in dir when `errorWhenNoFilesFound` and `warnOnError` ar onwarn(warning) { t.deepEqual( warning.message, - `No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${require.resolve( + `No files found in ./module-dir-c/*.js when trying to dynamically load concatted string from ${posix.resolve( + DIRNAME, './fixtures/fixture-no-files.js' )}` ); diff --git a/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.md b/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.mjs.md similarity index 99% rename from packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.md rename to packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.mjs.md index 0889053e5..4d6d8928e 100644 --- a/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.md +++ b/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/rollup-plugin-dynamic-import-vars.test.js` +# Snapshot report for `test/rollup-plugin-dynamic-import-vars.test.mjs` -The actual snapshot is saved in `rollup-plugin-dynamic-import-vars.test.js.snap`. +The actual snapshot is saved in `rollup-plugin-dynamic-import-vars.test.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.snap b/packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.mjs.snap similarity index 100% rename from packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.snap rename to packages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.mjs.snap diff --git a/packages/inject/package.json b/packages/inject/package.json index 7ecabd25f..09dd55a17 100644 --- a/packages/inject/package.json +++ b/packages/inject/package.json @@ -62,7 +62,7 @@ }, "dependencies": { "@rollup/pluginutils": "^5.0.1", - "estree-walker": "^2.0.2", + "estree-walker": "^3.0.3", "magic-string": "^0.30.3" }, "devDependencies": { diff --git a/packages/inject/test/node_modules/current-package b/packages/inject/test/node_modules/current-package new file mode 120000 index 000000000..6581736d6 --- /dev/null +++ b/packages/inject/test/node_modules/current-package @@ -0,0 +1 @@ +../../ \ No newline at end of file diff --git a/packages/inject/test/snapshots/test.js.md b/packages/inject/test/snapshots/test.mjs.md similarity index 97% rename from packages/inject/test/snapshots/test.js.md rename to packages/inject/test/snapshots/test.mjs.md index b82323573..5c2f437a3 100644 --- a/packages/inject/test/snapshots/test.js.md +++ b/packages/inject/test/snapshots/test.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/test.js` +# Snapshot report for `test/test.mjs` -The actual snapshot is saved in `test.js.snap`. +The actual snapshot is saved in `test.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/packages/inject/test/snapshots/test.js.snap b/packages/inject/test/snapshots/test.mjs.snap similarity index 100% rename from packages/inject/test/snapshots/test.js.snap rename to packages/inject/test/snapshots/test.mjs.snap diff --git a/packages/inject/test/test.js b/packages/inject/test/test.mjs similarity index 93% rename from packages/inject/test/test.js rename to packages/inject/test/test.mjs index 5f5ee27e3..452e10d77 100644 --- a/packages/inject/test/test.js +++ b/packages/inject/test/test.mjs @@ -1,11 +1,11 @@ -const fs = require('fs'); -const path = require('path'); -const os = require('os'); +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; -const acorn = require('acorn'); -const test = require('ava'); +import * as acorn from 'acorn'; +import test from 'ava'; -const inject = require('..'); +import inject from 'current-package'; const compare = (t, fixture, options) => { const filename = path.resolve(`test/fixtures/${fixture}/input.js`); diff --git a/packages/pluginutils/package.json b/packages/pluginutils/package.json index 2745ddcce..6650fada1 100644 --- a/packages/pluginutils/package.json +++ b/packages/pluginutils/package.json @@ -62,7 +62,7 @@ }, "dependencies": { "@types/estree": "^1.0.0", - "estree-walker": "^2.0.2", + "estree-walker": "^3.0.3", "picomatch": "^2.3.1" }, "devDependencies": { diff --git a/packages/pluginutils/src/attachScopes.ts b/packages/pluginutils/src/attachScopes.ts index fc6392ddb..6800deac1 100755 --- a/packages/pluginutils/src/attachScopes.ts +++ b/packages/pluginutils/src/attachScopes.ts @@ -106,7 +106,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc } // create new block scope - if (node.type === 'BlockStatement' && !/Function/.test(parent.type)) { + if (node.type === 'BlockStatement' && parent && !/Function/.test(parent.type)) { newScope = new Scope({ parent: scope, block: true diff --git a/packages/pluginutils/types/index.d.ts b/packages/pluginutils/types/index.d.ts index 4bdf3a2a6..8f50e0c8f 100755 --- a/packages/pluginutils/types/index.d.ts +++ b/packages/pluginutils/types/index.d.ts @@ -1,10 +1,10 @@ -import type { BaseNode } from 'estree'; +import type { Node } from 'estree'; export interface AttachedScope { parent?: AttachedScope; isBlockScope: boolean; declarations: { [key: string]: boolean }; - addDeclaration(node: BaseNode, isBlockDeclaration: boolean, isVar: boolean): void; + addDeclaration(node: Node, isBlockDeclaration: boolean, isVar: boolean): void; contains(name: string): boolean; } @@ -37,7 +37,7 @@ export function addExtension(filename: string, ext?: string): string; * Each `Scope` object has a `scope.contains(name)` method that returns `true` * if a given name is defined in the current scope or a parent scope. */ -export function attachScopes(ast: BaseNode, propertyName?: string): AttachedScope; +export function attachScopes(ast: Node, propertyName?: string): AttachedScope; /** * Constructs a filter function which can be used to determine whether or not @@ -66,7 +66,7 @@ export function dataToEsm(data: unknown, options?: DataToEsmOptions): string; * Extracts the names of all assignment targets based upon specified patterns. * @param param An `acorn` AST Node. */ -export function extractAssignedNames(param: BaseNode): string[]; +export function extractAssignedNames(param: Node): string[]; /** * Constructs a bundle-safe identifier from a `string`. diff --git a/packages/strip/package.json b/packages/strip/package.json index b3272cede..d80ef934d 100644 --- a/packages/strip/package.json +++ b/packages/strip/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@rollup/pluginutils": "^5.0.1", - "estree-walker": "^2.0.2", + "estree-walker": "^3.0.3", "magic-string": "^0.30.3" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f75e203e..57b264073 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -203,8 +203,8 @@ importers: specifier: ^1.0.1 version: 1.0.1 estree-walker: - specifier: ^2.0.2 - version: 2.0.2 + specifier: ^3.0.3 + version: 3.0.3 fdir: specifier: ^6.2.0 version: 6.3.0(picomatch@4.0.2) @@ -293,8 +293,8 @@ importers: specifier: ^1.8.5 version: 1.8.5 estree-walker: - specifier: ^2.0.2 - version: 2.0.2 + specifier: ^3.0.3 + version: 3.0.3 fast-glob: specifier: ^3.2.12 version: 3.2.12 @@ -409,8 +409,8 @@ importers: specifier: ^5.0.1 version: 5.0.1(rollup@4.0.0-24) estree-walker: - specifier: ^2.0.2 - version: 2.0.2 + specifier: ^3.0.3 + version: 3.0.3 magic-string: specifier: ^0.30.3 version: 0.30.3 @@ -532,10 +532,10 @@ importers: dependencies: '@types/estree': specifier: ^1.0.0 - version: 1.0.0 + version: 1.0.6 estree-walker: - specifier: ^2.0.2 - version: 2.0.2 + specifier: ^3.0.3 + version: 3.0.3 picomatch: specifier: ^2.3.1 version: 2.3.1 @@ -621,8 +621,8 @@ importers: specifier: ^5.0.1 version: 5.0.1(rollup@4.0.0-24) estree-walker: - specifier: ^2.0.2 - version: 2.0.2 + specifier: ^3.0.3 + version: 3.0.3 magic-string: specifier: ^0.30.3 version: 0.30.3 @@ -1772,6 +1772,9 @@ packages: '@types/estree@1.0.0': resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} + '@types/estree@1.0.6': + resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} + '@types/http-cache-semantics@4.0.1': resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} @@ -2690,6 +2693,9 @@ packages: estree-walker@2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -5623,7 +5629,7 @@ snapshots: '@rollup/pluginutils@5.1.0(rollup@4.0.0-24)': dependencies: - '@types/estree': 1.0.0 + '@types/estree': 1.0.6 estree-walker: 2.0.2 picomatch: 2.3.1 optionalDependencies: @@ -5773,11 +5779,13 @@ snapshots: '@types/eslint@8.4.6': dependencies: - '@types/estree': 1.0.0 + '@types/estree': 1.0.6 '@types/json-schema': 7.0.11 '@types/estree@1.0.0': {} + '@types/estree@1.0.6': {} + '@types/http-cache-semantics@4.0.1': {} '@types/json-schema@7.0.11': {} @@ -6923,6 +6931,10 @@ snapshots: estree-walker@2.0.2: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.6 + esutils@2.0.3: {} eventemitter3@4.0.7: {} @@ -7305,7 +7317,7 @@ snapshots: is-reference@1.2.1: dependencies: - '@types/estree': 1.0.0 + '@types/estree': 1.0.6 is-regex@1.1.4: dependencies: