es-check 9.4.2 → 9.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.js +6 -0
- package/index.js +2 -2
- package/package.json +1 -1
- package/utils.js +16 -45
package/constants.js
CHANGED
|
@@ -716,6 +716,11 @@ const JS_VERSIONS = [
|
|
|
716
716
|
'es13', 'es2022', 'es14', 'es2023', 'es15', 'es2024', 'es16', 'es2025', 'checkBrowser'
|
|
717
717
|
];
|
|
718
718
|
|
|
719
|
+
const VERSION_ORDER = [
|
|
720
|
+
'es5', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019',
|
|
721
|
+
'es2020', 'es2021', 'es2022', 'es2023', 'es2024', 'es2025'
|
|
722
|
+
];
|
|
723
|
+
|
|
719
724
|
/**
|
|
720
725
|
* Maps feature names from ES_FEATURES to their polyfill patterns.
|
|
721
726
|
* This version uses standardized keys and robust regex for both manual and module polyfills.
|
|
@@ -798,4 +803,5 @@ module.exports = {
|
|
|
798
803
|
BROWSER_TO_ES_VERSION,
|
|
799
804
|
FEATURE_TO_POLYFILL_MAP,
|
|
800
805
|
JS_VERSIONS,
|
|
806
|
+
VERSION_ORDER,
|
|
801
807
|
};
|
package/index.js
CHANGED
|
@@ -492,8 +492,8 @@ async function runChecks(configs, loggerOrOptions) {
|
|
|
492
492
|
|
|
493
493
|
const needsFullAST = checkFeatures;
|
|
494
494
|
const parserOptions = needsFullAST ? acornOpts : { ...acornOpts, locations: false, ranges: false, onComment: null };
|
|
495
|
-
|
|
496
|
-
const { ast, error: parseError } = parseCode(code, parserOptions, acorn, file
|
|
495
|
+
|
|
496
|
+
const { ast, error: parseError } = parseCode(code, parserOptions, acorn, file);
|
|
497
497
|
if (parseError) {
|
|
498
498
|
if (isDebug) {
|
|
499
499
|
logger.debug(`ES-Check: failed to parse file: ${file} \n - error: ${parseError.err}`)
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const winston = require('winston');
|
|
3
3
|
const supportsColor = require('supports-color');
|
|
4
|
+
const { fastBrakeSync } = require('fast-brake/sync');
|
|
5
|
+
const esversionPlugin = require('fast-brake/plugins/esversion');
|
|
6
|
+
const fastbrake = fastBrakeSync({ plugins: [esversionPlugin.default] });
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Parse ignore list from options
|
|
@@ -487,59 +490,26 @@ function getTargetVersion(ecmaVersion) {
|
|
|
487
490
|
}
|
|
488
491
|
|
|
489
492
|
/**
|
|
490
|
-
* Parse code with
|
|
493
|
+
* Parse code with Acorn and handle errors
|
|
491
494
|
* @param {string} code - Code to parse
|
|
492
|
-
* @param {Object} acornOpts - Parsing options
|
|
493
|
-
* @param {Object} acorn -
|
|
495
|
+
* @param {Object} acornOpts - Parsing options
|
|
496
|
+
* @param {Object} acorn - Acorn parser instance
|
|
494
497
|
* @param {string} file - File path for error reporting
|
|
495
498
|
* @returns {{ast: Object, error: null} | {ast: null, error: Object}}
|
|
496
499
|
*/
|
|
497
|
-
|
|
498
|
-
const esversionPlugin = require('fast-brake/plugins/esversion');
|
|
499
|
-
|
|
500
|
-
const fastbrake = fastBrakeSync({ plugins: [esversionPlugin.default] });
|
|
501
|
-
const parseCache = new Map();
|
|
502
|
-
|
|
503
|
-
function parseCode(code, acornOpts, acorn, file, needsFeatures = false) {
|
|
504
|
-
const cacheKey = `${file}:${acornOpts.ecmaVersion}:${acornOpts.sourceType}:${needsFeatures}:${code.length}`;
|
|
505
|
-
|
|
506
|
-
if (parseCache.has(cacheKey)) {
|
|
507
|
-
return parseCache.get(cacheKey);
|
|
508
|
-
}
|
|
509
|
-
|
|
500
|
+
function parseCode(code, acornOpts, acorn, file) {
|
|
510
501
|
try {
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
const sourceType = acornOpts.sourceType || 'script';
|
|
514
|
-
|
|
515
|
-
const codeToCheck = acornOpts.allowHashBang && code.startsWith('#!')
|
|
516
|
-
? code.slice(code.indexOf('\n') + 1)
|
|
517
|
-
: code;
|
|
518
|
-
|
|
519
|
-
const options = { target: targetVersion, sourceType };
|
|
520
|
-
|
|
521
|
-
const isCompatible = fastbrake.check(codeToCheck, options);
|
|
522
|
-
if (!isCompatible) {
|
|
523
|
-
throw new Error(`Code contains features incompatible with ${targetVersion}`);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
const detectedFeatures = needsFeatures
|
|
527
|
-
? fastbrake.detect(codeToCheck)
|
|
528
|
-
: [];
|
|
529
|
-
|
|
530
|
-
const result = {
|
|
531
|
-
ast: { type: 'Program', features: detectedFeatures },
|
|
532
|
-
error: null
|
|
533
|
-
};
|
|
534
|
-
parseCache.set(cacheKey, result);
|
|
535
|
-
return result;
|
|
502
|
+
const ast = acorn.parse(code, acornOpts);
|
|
503
|
+
return { ast, error: null };
|
|
536
504
|
} catch (err) {
|
|
537
|
-
|
|
505
|
+
return {
|
|
538
506
|
ast: null,
|
|
539
|
-
error: {
|
|
507
|
+
error: {
|
|
508
|
+
err,
|
|
509
|
+
stack: err.stack,
|
|
510
|
+
file
|
|
511
|
+
}
|
|
540
512
|
};
|
|
541
|
-
parseCache.set(cacheKey, result);
|
|
542
|
-
return result;
|
|
543
513
|
}
|
|
544
514
|
}
|
|
545
515
|
|
|
@@ -605,6 +575,7 @@ function handleESVersionError(options) {
|
|
|
605
575
|
}
|
|
606
576
|
}
|
|
607
577
|
|
|
578
|
+
|
|
608
579
|
function parseLightMode(code, ecmaVersion, isModule, allowHashBang, file) {
|
|
609
580
|
const targetVersion = getTargetVersion(ecmaVersion);
|
|
610
581
|
|