2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

fix: error unexpected token in fetch JS compatibility issue with Webpack 4 (#10864)

* chore: added npm run lint step between install and build in build-and-run-vitest

* chore: acorn ^8.16.0 added as a devDependency

* test: added test to parse all lib files via acorn

* feat: added globalThis: "readonly"

* feat: ?? replaced with the verbose ternary
This commit is contained in:
Jay
2026-05-07 19:36:11 +02:00
committed by GitHub
parent c4453bab70
commit 3e6b4e1f31
6 changed files with 48 additions and 4 deletions
+2
View File
@@ -27,6 +27,8 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Lint
run: npm run lint
- name: Build project
run: npm run build
- name: Install Playwright with deps
+10 -3
View File
@@ -33,20 +33,27 @@ export default [
languageOptions: {
globals: {
...globals.browser,
...globals.node
...globals.node,
globalThis: 'readonly'
}
}
},
{
files: ['lib/adapters/http.js', 'lib/platform/node/**/*.js'],
languageOptions: {
globals: globals.node
globals: {
...globals.node,
globalThis: 'readonly'
}
}
},
{
files: ['lib/adapters/xhr.js', 'lib/platform/browser/**/*.js'],
languageOptions: {
globals: globals.browser
globals: {
...globals.browser,
globalThis: 'readonly'
}
}
}
];
+4 -1
View File
@@ -28,7 +28,10 @@ const test = (fn, ...args) => {
};
const factory = (env) => {
const globalObject = utils.global ?? globalThis;
const globalObject =
utils.global !== undefined && utils.global !== null
? utils.global
: globalThis;
const { ReadableStream, TextEncoder } = globalObject;
env = utils.merge.call(
+1
View File
@@ -29,6 +29,7 @@
"@vitest/browser": "^4.1.5",
"@vitest/browser-playwright": "^4.1.5",
"abortcontroller-polyfill": "^1.7.8",
"acorn": "^8.16.0",
"body-parser": "^2.2.2",
"chalk": "^5.6.2",
"cross-env": "^10.1.0",
+1
View File
@@ -141,6 +141,7 @@
"@vitest/browser": "^4.1.5",
"@vitest/browser-playwright": "^4.1.5",
"abortcontroller-polyfill": "^1.7.8",
"acorn": "^8.16.0",
"body-parser": "^2.2.2",
"chalk": "^5.6.2",
"cross-env": "^10.1.0",
+30
View File
@@ -0,0 +1,30 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Parser } from 'acorn';
const LIB_DIR = fileURLToPath(new URL('../../lib/', import.meta.url));
const ECMA_VERSION = 2018;
function walk(dir) {
const out = [];
for (const name of readdirSync(dir)) {
const full = join(dir, name);
if (statSync(full).isDirectory()) out.push(...walk(full));
else if (full.endsWith('.js')) out.push(full);
}
return out;
}
describe('lib/ source files parse as ES2018', () => {
for (const file of walk(LIB_DIR)) {
const rel = file.slice(LIB_DIR.length);
it(rel, () => {
const src = readFileSync(file, 'utf8');
expect(() =>
Parser.parse(src, { ecmaVersion: ECMA_VERSION, sourceType: 'module' })
).not.toThrow();
});
}
});