123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- "use strict";
- const DEFAULT_ECMA_VERSION = 5;
- const SUPPORTED_VERSIONS = [
- 3,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10,
- 11,
- 12
- ];
- function normalizeEcmaVersion(ecmaVersion = DEFAULT_ECMA_VERSION) {
- if (typeof ecmaVersion !== "number") {
- throw new Error(`ecmaVersion must be a number. Received value of type ${typeof ecmaVersion} instead.`);
- }
- let version = ecmaVersion;
-
-
- if (version >= 2015) {
- version -= 2009;
- }
- if (!SUPPORTED_VERSIONS.includes(version)) {
- throw new Error("Invalid ecmaVersion.");
- }
- return version;
- }
- function normalizeSourceType(sourceType = "script") {
- if (sourceType === "script" || sourceType === "module") {
- return sourceType;
- }
- throw new Error("Invalid sourceType.");
- }
- function normalizeOptions(options) {
- const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
- const sourceType = normalizeSourceType(options.sourceType);
- const ranges = options.range === true;
- const locations = options.loc === true;
- if (sourceType === "module" && ecmaVersion < 6) {
- throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
- }
- return Object.assign({}, options, { ecmaVersion, sourceType, ranges, locations });
- }
- function getLatestEcmaVersion() {
- return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
- }
- function getSupportedEcmaVersions() {
- return [...SUPPORTED_VERSIONS];
- }
- module.exports = {
- normalizeOptions,
- getLatestEcmaVersion,
- getSupportedEcmaVersions
- };
|