4208 changed files with 457917 additions and 424548 deletions
File diff suppressed because it is too large
@ -1,343 +0,0 @@ |
|||
export { debounce, throttle } from 'throttle-debounce'; |
|||
|
|||
/** |
|||
* Promise, or maybe not |
|||
*/ |
|||
declare type Awaitable<T> = T | PromiseLike<T>; |
|||
/** |
|||
* Null or whatever |
|||
*/ |
|||
declare type Nullable<T> = T | null | undefined; |
|||
/** |
|||
* Array, or not yet |
|||
*/ |
|||
declare type Arrayable<T> = T | Array<T>; |
|||
/** |
|||
* Function |
|||
*/ |
|||
declare type Fn<T = void> = () => T; |
|||
/** |
|||
* Constructor |
|||
*/ |
|||
declare type Constructor<T = void> = new (...args: any[]) => T; |
|||
/** |
|||
* Infers the element type of an array |
|||
*/ |
|||
declare type ElementOf<T> = T extends (infer E)[] ? E : never; |
|||
/** |
|||
* Defines an intersection type of all union items. |
|||
* |
|||
* @param U Union of any types that will be intersected. |
|||
* @returns U items intersected |
|||
* @see https://stackoverflow.com/a/50375286/9259330
|
|||
*/ |
|||
declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; |
|||
/** |
|||
* Infers the arguments type of a function |
|||
*/ |
|||
declare type ArgumentsType<T> = T extends ((...args: infer A) => any) ? A : never; |
|||
declare type MergeInsertions<T> = T extends object ? { |
|||
[K in keyof T]: MergeInsertions<T[K]>; |
|||
} : T; |
|||
declare type DeepMerge<F, S> = MergeInsertions<{ |
|||
[K in keyof F | keyof S]: K extends keyof S & keyof F ? DeepMerge<F[K], S[K]> : K extends keyof S ? S[K] : K extends keyof F ? F[K] : never; |
|||
}>; |
|||
|
|||
/** |
|||
* Convert `Arrayable<T>` to `Array<T>` |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>; |
|||
/** |
|||
* Convert `Arrayable<T>` to `Array<T>` and flatten it |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function flattenArrayable<T>(array?: Nullable<Arrayable<T | Array<T>>>): Array<T>; |
|||
/** |
|||
* Use rest arguments to merge arrays |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>; |
|||
declare type PartitionFilter<T> = (i: T, idx: number, arr: readonly T[]) => any; |
|||
/** |
|||
* Divide an array into two parts by a filter function |
|||
* |
|||
* @category Array |
|||
* @example const [odd, even] = partition([1, 2, 3, 4], i => i % 2 != 0) |
|||
*/ |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>): [T[], T[]]; |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>, f2: PartitionFilter<T>): [T[], T[], T[]]; |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>, f2: PartitionFilter<T>, f3: PartitionFilter<T>): [T[], T[], T[], T[]]; |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>, f2: PartitionFilter<T>, f3: PartitionFilter<T>, f4: PartitionFilter<T>): [T[], T[], T[], T[], T[]]; |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>, f2: PartitionFilter<T>, f3: PartitionFilter<T>, f4: PartitionFilter<T>, f5: PartitionFilter<T>): [T[], T[], T[], T[], T[], T[]]; |
|||
declare function partition<T>(array: readonly T[], f1: PartitionFilter<T>, f2: PartitionFilter<T>, f3: PartitionFilter<T>, f4: PartitionFilter<T>, f5: PartitionFilter<T>, f6: PartitionFilter<T>): [T[], T[], T[], T[], T[], T[], T[]]; |
|||
/** |
|||
* Unique an Array |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function uniq<T>(array: readonly T[]): T[]; |
|||
/** |
|||
* Get last item |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function last(array: readonly []): undefined; |
|||
declare function last<T>(array: readonly T[]): T; |
|||
/** |
|||
* Remove an item from Array |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function remove<T>(array: T[], value: T): boolean; |
|||
/** |
|||
* Get nth item of Array. Negative for backward |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function at(array: readonly [], index: number): undefined; |
|||
declare function at<T>(array: readonly T[], index: number): T; |
|||
/** |
|||
* Genrate a range array of numbers. The `stop` is exclusive. |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function range(stop: number): number[]; |
|||
declare function range(start: number, stop: number, step?: number): number[]; |
|||
/** |
|||
* Move element in an Array |
|||
* |
|||
* @category Array |
|||
* @param arr |
|||
* @param from |
|||
* @param to |
|||
*/ |
|||
declare function move<T>(arr: T[], from: number, to: number): T[]; |
|||
/** |
|||
* Clamp a number to the index ranage of an array |
|||
* |
|||
* @category Array |
|||
*/ |
|||
declare function clampArrayRange(n: number, arr: readonly unknown[]): number; |
|||
|
|||
declare const assert: (condition: boolean, message: string) => asserts condition; |
|||
declare const toString: (v: any) => string; |
|||
declare const noop: () => void; |
|||
|
|||
/** |
|||
* Type guard to filter out null-ish values |
|||
* |
|||
* @category Guards |
|||
* @example array.filter(notNullish) |
|||
*/ |
|||
declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>; |
|||
/** |
|||
* Type guard to filter out null values |
|||
* |
|||
* @category Guards |
|||
* @example array.filter(noNull) |
|||
*/ |
|||
declare function noNull<T>(v: T | null): v is Exclude<T, null>; |
|||
/** |
|||
* Type guard to filter out null-ish values |
|||
* |
|||
* @category Guards |
|||
* @example array.filter(notUndefined) |
|||
*/ |
|||
declare function notUndefined<T>(v: T): v is Exclude<T, undefined>; |
|||
/** |
|||
* Type guard to filter out falsy values |
|||
* |
|||
* @category Guards |
|||
* @example array.filter(isTruthy) |
|||
*/ |
|||
declare function isTruthy<T>(v: T): v is NonNullable<T>; |
|||
|
|||
declare const isDef: <T = any>(val?: T | undefined) => val is T; |
|||
declare const isBoolean: (val: any) => val is boolean; |
|||
declare const isFunction: <T extends Function>(val: any) => val is T; |
|||
declare const isNumber: (val: any) => val is number; |
|||
declare const isString: (val: unknown) => val is string; |
|||
declare const isObject: (val: any) => val is object; |
|||
declare const isWindow: (val: any) => boolean; |
|||
declare const isBrowser: boolean; |
|||
|
|||
declare function clamp(n: number, min: number, max: number): number; |
|||
declare function sum(...args: number[] | number[][]): number; |
|||
|
|||
/** |
|||
* Replace backslash to slash |
|||
* |
|||
* @category String |
|||
*/ |
|||
declare function slash(str: string): string; |
|||
/** |
|||
* Ensure prefix of a string |
|||
* |
|||
* @category String |
|||
*/ |
|||
declare function ensurePrefix(prefix: string, str: string): string; |
|||
/** |
|||
* Dead simple template engine, just like Python's `.format()` |
|||
* |
|||
* @example |
|||
* ``` |
|||
* const result = template( |
|||
* 'Hello {0}! My name is {1}.', |
|||
* 'Inès', |
|||
* 'Anthony' |
|||
* ) // Hello Inès! My name is Anthony.
|
|||
* ``` |
|||
*/ |
|||
declare function template(str: string, ...args: any[]): string; |
|||
|
|||
declare const timestamp: () => number; |
|||
|
|||
/** |
|||
* Call every function in an array |
|||
*/ |
|||
declare function batchInvoke(functions: Nullable<Fn>[]): void; |
|||
/** |
|||
* Call the function |
|||
*/ |
|||
declare function invoke(fn: Fn): void; |
|||
/** |
|||
* Pass the value through the callback, and return the value |
|||
* |
|||
* @example |
|||
* ``` |
|||
* function createUser(name: string): User { |
|||
* return tap(new User, user => { |
|||
* user.name = name |
|||
* }) |
|||
* } |
|||
* ``` |
|||
*/ |
|||
declare function tap<T>(value: T, callback: (value: T) => void): T; |
|||
|
|||
/** |
|||
* Map key/value pairs for an object, and construct a new one |
|||
* |
|||
* |
|||
* @category Object |
|||
* |
|||
* Transform: |
|||
* @example |
|||
* ``` |
|||
* objectMap({ a: 1, b: 2 }, (k, v) => [k.toString().toUpperCase(), v.toString()]) |
|||
* // { A: '1', B: '2' }
|
|||
* ``` |
|||
* |
|||
* Swap key/value: |
|||
* @example |
|||
* ``` |
|||
* objectMap({ a: 1, b: 2 }, (k, v) => [v, k]) |
|||
* // { 1: 'a', 2: 'b' }
|
|||
* ``` |
|||
* |
|||
* Filter keys: |
|||
* @example |
|||
* ``` |
|||
* objectMap({ a: 1, b: 2 }, (k, v) => k === 'a' ? undefined : [k, v]) |
|||
* // { b: 2 }
|
|||
* ``` |
|||
*/ |
|||
declare function objectMap<K extends string, V, NK = K, NV = V>(obj: Record<K, V>, fn: (key: K, value: V) => [NK, NV] | undefined): Record<K, V>; |
|||
/** |
|||
* Type guard for any key, `k`. |
|||
* Marks `k` as a key of `T` if `k` is in `obj`. |
|||
* |
|||
* @category Object |
|||
* @param obj object to query for key `k` |
|||
* @param k key to check existence in `obj` |
|||
*/ |
|||
declare function isKeyOf<T extends object>(obj: T, k: keyof any): k is keyof T; |
|||
/** |
|||
* Strict typed `Object.keys` |
|||
* |
|||
* @category Object |
|||
*/ |
|||
declare function objectKeys<T extends object>(obj: T): (keyof T)[]; |
|||
/** |
|||
* Strict typed `Object.entries` |
|||
* |
|||
* @category Object |
|||
*/ |
|||
declare function objectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][]; |
|||
/** |
|||
* Deep merge :P |
|||
* |
|||
* @category Object |
|||
*/ |
|||
declare function deepMerge<T extends object = object, S extends object = T>(target: T, ...sources: S[]): DeepMerge<T, S>; |
|||
/** |
|||
* Create a new subset object by giving keys |
|||
* |
|||
* @category Object |
|||
*/ |
|||
declare function objectPick<O, T extends keyof O>(obj: O, keys: T[], omitUndefined?: boolean): Pick<O, T>; |
|||
/** |
|||
* Clear undefined fields from an object. It mutates the object |
|||
* |
|||
* @category Object |
|||
*/ |
|||
declare function clearUndefined<T extends object>(obj: T): T; |
|||
/** |
|||
* Determines whether an object has a property with the specified name |
|||
* |
|||
* @see https://eslint.org/docs/rules/no-prototype-builtins
|
|||
* @category Object |
|||
*/ |
|||
declare function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean; |
|||
|
|||
interface SingletonPromiseReturn<T> { |
|||
(): Promise<T>; |
|||
/** |
|||
* Reset current staled promise. |
|||
* Await it to have proper shutdown. |
|||
*/ |
|||
reset: () => Promise<void>; |
|||
} |
|||
/** |
|||
* Create singleton promise function |
|||
* |
|||
* @example |
|||
* ``` |
|||
* const promise = createSingletonPromise(async () => { ... }) |
|||
* |
|||
* await promise() |
|||
* await promise() // all of them will be bind to a single promise instance
|
|||
* await promise() // and be resolved together
|
|||
* ``` |
|||
*/ |
|||
declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>; |
|||
/** |
|||
* Promised `setTimeout` |
|||
*/ |
|||
declare function sleep(ms: number, callback?: Fn<any>): Promise<void>; |
|||
/** |
|||
* Create a promise lock |
|||
* |
|||
* @example |
|||
* ``` |
|||
* const lock = createPromiseLock() |
|||
* |
|||
* lock.run(async () => { |
|||
* await doSomething() |
|||
* }) |
|||
* |
|||
* // in anther context:
|
|||
* await lock.wait() // it will wait all tasking finished
|
|||
* ``` |
|||
*/ |
|||
declare function createPromiseLock(): { |
|||
run<T = void>(fn: () => Promise<T>): Promise<T>; |
|||
wait(): Promise<void>; |
|||
isWaiting(): boolean; |
|||
clear(): void; |
|||
}; |
|||
|
|||
export { ArgumentsType, Arrayable, Awaitable, Constructor, DeepMerge, ElementOf, Fn, MergeInsertions, Nullable, PartitionFilter, SingletonPromiseReturn, UnionToIntersection, assert, at, batchInvoke, clamp, clampArrayRange, clearUndefined, createPromiseLock, createSingletonPromise, deepMerge, ensurePrefix, flattenArrayable, hasOwnProperty, invoke, isBoolean, isBrowser, isDef, isFunction, isKeyOf, isNumber, isObject, isString, isTruthy, isWindow, last, mergeArrayable, move, noNull, noop, notNullish, notUndefined, objectEntries, objectKeys, objectMap, objectPick, partition, range, remove, slash, sleep, sum, tap, template, timestamp, toArray, toString, uniq }; |
|||
@ -1,430 +0,0 @@ |
|||
var __defProp = Object.defineProperty; |
|||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|||
var __getOwnPropNames = Object.getOwnPropertyNames; |
|||
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); |
|||
var __export = (target, all) => { |
|||
for (var name in all) |
|||
__defProp(target, name, { get: all[name], enumerable: true }); |
|||
}; |
|||
var __reExport = (target, module2, copyDefault, desc) => { |
|||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { |
|||
for (let key of __getOwnPropNames(module2)) |
|||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) |
|||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); |
|||
} |
|||
return target; |
|||
}; |
|||
var __toCommonJS = /* @__PURE__ */ ((cache) => { |
|||
return (module2, temp) => { |
|||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp); |
|||
}; |
|||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0); |
|||
|
|||
// src/index.ts
|
|||
var src_exports = {}; |
|||
__export(src_exports, { |
|||
assert: () => assert, |
|||
at: () => at, |
|||
batchInvoke: () => batchInvoke, |
|||
clamp: () => clamp, |
|||
clampArrayRange: () => clampArrayRange, |
|||
clearUndefined: () => clearUndefined, |
|||
createPromiseLock: () => createPromiseLock, |
|||
createSingletonPromise: () => createSingletonPromise, |
|||
debounce: () => debounce, |
|||
deepMerge: () => deepMerge, |
|||
ensurePrefix: () => ensurePrefix, |
|||
flattenArrayable: () => flattenArrayable, |
|||
hasOwnProperty: () => hasOwnProperty, |
|||
invoke: () => invoke, |
|||
isBoolean: () => isBoolean, |
|||
isBrowser: () => isBrowser, |
|||
isDef: () => isDef, |
|||
isFunction: () => isFunction, |
|||
isKeyOf: () => isKeyOf, |
|||
isNumber: () => isNumber, |
|||
isObject: () => isObject, |
|||
isString: () => isString, |
|||
isTruthy: () => isTruthy, |
|||
isWindow: () => isWindow, |
|||
last: () => last, |
|||
mergeArrayable: () => mergeArrayable, |
|||
move: () => move, |
|||
noNull: () => noNull, |
|||
noop: () => noop, |
|||
notNullish: () => notNullish, |
|||
notUndefined: () => notUndefined, |
|||
objectEntries: () => objectEntries, |
|||
objectKeys: () => objectKeys, |
|||
objectMap: () => objectMap, |
|||
objectPick: () => objectPick, |
|||
partition: () => partition, |
|||
range: () => range, |
|||
remove: () => remove, |
|||
slash: () => slash, |
|||
sleep: () => sleep, |
|||
sum: () => sum, |
|||
tap: () => tap, |
|||
template: () => template, |
|||
throttle: () => throttle, |
|||
timestamp: () => timestamp, |
|||
toArray: () => toArray, |
|||
toString: () => toString, |
|||
uniq: () => uniq |
|||
}); |
|||
|
|||
// src/math.ts
|
|||
function clamp(n, min, max) { |
|||
return Math.min(max, Math.max(min, n)); |
|||
} |
|||
function sum(...args) { |
|||
return flattenArrayable(args).reduce((a, b) => a + b, 0); |
|||
} |
|||
|
|||
// src/array.ts
|
|||
function toArray(array) { |
|||
array = array || []; |
|||
if (Array.isArray(array)) |
|||
return array; |
|||
return [array]; |
|||
} |
|||
function flattenArrayable(array) { |
|||
return toArray(array).flat(1); |
|||
} |
|||
function mergeArrayable(...args) { |
|||
return args.flatMap((i) => toArray(i)); |
|||
} |
|||
function partition(array, ...filters) { |
|||
const result = new Array(filters.length + 1).fill(null).map(() => []); |
|||
array.forEach((e, idx, arr) => { |
|||
let i = 0; |
|||
for (const filter of filters) { |
|||
if (filter(e, idx, arr)) { |
|||
result[i].push(e); |
|||
return; |
|||
} |
|||
i += 1; |
|||
} |
|||
result[i].push(e); |
|||
}); |
|||
return result; |
|||
} |
|||
function uniq(array) { |
|||
return Array.from(new Set(array)); |
|||
} |
|||
function last(array) { |
|||
return at(array, -1); |
|||
} |
|||
function remove(array, value) { |
|||
if (!array) |
|||
return false; |
|||
const index = array.indexOf(value); |
|||
if (index >= 0) { |
|||
array.splice(index, 1); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
function at(array, index) { |
|||
const len = array.length; |
|||
if (!len) |
|||
return void 0; |
|||
if (index < 0) |
|||
index += len; |
|||
return array[index]; |
|||
} |
|||
function range(...args) { |
|||
let start, stop, step; |
|||
if (args.length === 1) { |
|||
start = 0; |
|||
step = 1; |
|||
[stop] = args; |
|||
} else { |
|||
[start, stop, step = 1] = args; |
|||
} |
|||
const arr = []; |
|||
let current = start; |
|||
while (current < stop) { |
|||
arr.push(current); |
|||
current += step || 1; |
|||
} |
|||
return arr; |
|||
} |
|||
function move(arr, from, to) { |
|||
arr.splice(to, 0, arr.splice(from, 1)[0]); |
|||
return arr; |
|||
} |
|||
function clampArrayRange(n, arr) { |
|||
return clamp(n, 0, arr.length - 1); |
|||
} |
|||
|
|||
// src/base.ts
|
|||
var assert = (condition, message) => { |
|||
if (!condition) |
|||
throw new Error(message); |
|||
}; |
|||
var toString = (v) => Object.prototype.toString.call(v); |
|||
var noop = () => { |
|||
}; |
|||
|
|||
// src/guards.ts
|
|||
function notNullish(v) { |
|||
return v != null; |
|||
} |
|||
function noNull(v) { |
|||
return v !== null; |
|||
} |
|||
function notUndefined(v) { |
|||
return v !== void 0; |
|||
} |
|||
function isTruthy(v) { |
|||
return Boolean(v); |
|||
} |
|||
|
|||
// src/is.ts
|
|||
var isDef = (val) => typeof val !== "undefined"; |
|||
var isBoolean = (val) => typeof val === "boolean"; |
|||
var isFunction = (val) => typeof val === "function"; |
|||
var isNumber = (val) => typeof val === "number"; |
|||
var isString = (val) => typeof val === "string"; |
|||
var isObject = (val) => toString(val) === "[object Object]"; |
|||
var isWindow = (val) => typeof window !== "undefined" && toString(val) === "[object Window]"; |
|||
var isBrowser = typeof window !== "undefined"; |
|||
|
|||
// src/string.ts
|
|||
function slash(str) { |
|||
return str.replace(/\\/g, "/"); |
|||
} |
|||
function ensurePrefix(prefix, str) { |
|||
if (!str.startsWith(prefix)) |
|||
return prefix + str; |
|||
return str; |
|||
} |
|||
function template(str, ...args) { |
|||
return str.replace(/{(\d+)}/g, (match, key) => { |
|||
const index = Number(key); |
|||
if (Number.isNaN(index)) |
|||
return match; |
|||
return args[index]; |
|||
}); |
|||
} |
|||
|
|||
// src/time.ts
|
|||
var timestamp = () => +Date.now(); |
|||
|
|||
// src/function.ts
|
|||
function batchInvoke(functions) { |
|||
functions.forEach((fn) => fn && fn()); |
|||
} |
|||
function invoke(fn) { |
|||
return fn(); |
|||
} |
|||
function tap(value, callback) { |
|||
callback(value); |
|||
return value; |
|||
} |
|||
|
|||
// src/object.ts
|
|||
function objectMap(obj, fn) { |
|||
return Object.fromEntries(Object.entries(obj).map(([k, v]) => fn(k, v)).filter(notNullish)); |
|||
} |
|||
function isKeyOf(obj, k) { |
|||
return k in obj; |
|||
} |
|||
function objectKeys(obj) { |
|||
return Object.keys(obj); |
|||
} |
|||
function objectEntries(obj) { |
|||
return Object.entries(obj); |
|||
} |
|||
function deepMerge(target, ...sources) { |
|||
if (!sources.length) |
|||
return target; |
|||
const source = sources.shift(); |
|||
if (source === void 0) |
|||
return target; |
|||
if (isMergableObject(target) && isMergableObject(source)) { |
|||
objectKeys(source).forEach((key) => { |
|||
if (isMergableObject(source[key])) { |
|||
if (!target[key]) |
|||
target[key] = {}; |
|||
deepMerge(target[key], source[key]); |
|||
} else { |
|||
target[key] = source[key]; |
|||
} |
|||
}); |
|||
} |
|||
return deepMerge(target, ...sources); |
|||
} |
|||
function isMergableObject(item) { |
|||
return isObject(item) && !Array.isArray(item); |
|||
} |
|||
function objectPick(obj, keys, omitUndefined = false) { |
|||
return keys.reduce((n, k) => { |
|||
if (k in obj) { |
|||
if (!omitUndefined || !obj[k] === void 0) |
|||
n[k] = obj[k]; |
|||
} |
|||
return n; |
|||
}, {}); |
|||
} |
|||
function clearUndefined(obj) { |
|||
Object.keys(obj).forEach((key) => obj[key] === void 0 ? delete obj[key] : {}); |
|||
return obj; |
|||
} |
|||
function hasOwnProperty(obj, v) { |
|||
if (obj == null) |
|||
return false; |
|||
return Object.prototype.hasOwnProperty.call(obj, v); |
|||
} |
|||
|
|||
// src/promise.ts
|
|||
function createSingletonPromise(fn) { |
|||
let _promise; |
|||
function wrapper() { |
|||
if (!_promise) |
|||
_promise = fn(); |
|||
return _promise; |
|||
} |
|||
wrapper.reset = async () => { |
|||
const _prev = _promise; |
|||
_promise = void 0; |
|||
if (_prev) |
|||
await _prev; |
|||
}; |
|||
return wrapper; |
|||
} |
|||
function sleep(ms, callback) { |
|||
return new Promise((resolve) => setTimeout(async () => { |
|||
await (callback == null ? void 0 : callback()); |
|||
resolve(); |
|||
}, ms)); |
|||
} |
|||
function createPromiseLock() { |
|||
const locks = []; |
|||
return { |
|||
async run(fn) { |
|||
const p = fn(); |
|||
locks.push(p); |
|||
try { |
|||
return await p; |
|||
} finally { |
|||
remove(locks, p); |
|||
} |
|||
}, |
|||
async wait() { |
|||
await Promise.allSettled(locks); |
|||
}, |
|||
isWaiting() { |
|||
return Boolean(locks.length); |
|||
}, |
|||
clear() { |
|||
locks.length = 0; |
|||
} |
|||
}; |
|||
} |
|||
|
|||
// node_modules/.pnpm/throttle-debounce@3.0.1/node_modules/throttle-debounce/esm/index.js
|
|||
function throttle(delay, noTrailing, callback, debounceMode) { |
|||
var timeoutID; |
|||
var cancelled = false; |
|||
var lastExec = 0; |
|||
function clearExistingTimeout() { |
|||
if (timeoutID) { |
|||
clearTimeout(timeoutID); |
|||
} |
|||
} |
|||
function cancel() { |
|||
clearExistingTimeout(); |
|||
cancelled = true; |
|||
} |
|||
if (typeof noTrailing !== "boolean") { |
|||
debounceMode = callback; |
|||
callback = noTrailing; |
|||
noTrailing = void 0; |
|||
} |
|||
function wrapper() { |
|||
for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) { |
|||
arguments_[_key] = arguments[_key]; |
|||
} |
|||
var self = this; |
|||
var elapsed = Date.now() - lastExec; |
|||
if (cancelled) { |
|||
return; |
|||
} |
|||
function exec() { |
|||
lastExec = Date.now(); |
|||
callback.apply(self, arguments_); |
|||
} |
|||
function clear() { |
|||
timeoutID = void 0; |
|||
} |
|||
if (debounceMode && !timeoutID) { |
|||
exec(); |
|||
} |
|||
clearExistingTimeout(); |
|||
if (debounceMode === void 0 && elapsed > delay) { |
|||
exec(); |
|||
} else if (noTrailing !== true) { |
|||
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === void 0 ? delay - elapsed : delay); |
|||
} |
|||
} |
|||
wrapper.cancel = cancel; |
|||
return wrapper; |
|||
} |
|||
function debounce(delay, atBegin, callback) { |
|||
return callback === void 0 ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false); |
|||
} |
|||
module.exports = __toCommonJS(src_exports); |
|||
// Annotate the CommonJS export names for ESM import in node:
|
|||
0 && (module.exports = { |
|||
assert, |
|||
at, |
|||
batchInvoke, |
|||
clamp, |
|||
clampArrayRange, |
|||
clearUndefined, |
|||
createPromiseLock, |
|||
createSingletonPromise, |
|||
debounce, |
|||
deepMerge, |
|||
ensurePrefix, |
|||
flattenArrayable, |
|||
hasOwnProperty, |
|||
invoke, |
|||
isBoolean, |
|||
isBrowser, |
|||
isDef, |
|||
isFunction, |
|||
isKeyOf, |
|||
isNumber, |
|||
isObject, |
|||
isString, |
|||
isTruthy, |
|||
isWindow, |
|||
last, |
|||
mergeArrayable, |
|||
move, |
|||
noNull, |
|||
noop, |
|||
notNullish, |
|||
notUndefined, |
|||
objectEntries, |
|||
objectKeys, |
|||
objectMap, |
|||
objectPick, |
|||
partition, |
|||
range, |
|||
remove, |
|||
slash, |
|||
sleep, |
|||
sum, |
|||
tap, |
|||
template, |
|||
throttle, |
|||
timestamp, |
|||
toArray, |
|||
toString, |
|||
uniq |
|||
}); |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||
{"version":3,"names":[],"sources":["../src/index.ts"],"sourcesContent":["export {\n isIdentifierName,\n isIdentifierChar,\n isIdentifierStart,\n} from \"./identifier\";\nexport {\n isReservedWord,\n isStrictBindOnlyReservedWord,\n isStrictBindReservedWord,\n isStrictReservedWord,\n isKeyword,\n} from \"./keyword\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAKA"} |
|||
{"version":3,"names":["_identifier","require","_keyword"],"sources":["../src/index.ts"],"sourcesContent":["export {\n isIdentifierName,\n isIdentifierChar,\n isIdentifierStart,\n} from \"./identifier.ts\";\nexport {\n isReservedWord,\n isStrictBindOnlyReservedWord,\n isStrictBindReservedWord,\n isStrictReservedWord,\n isKeyword,\n} from \"./keyword.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA"} |
|||
@ -1 +1 @@ |
|||
{"version":3,"names":["reservedWords","keyword","strict","strictBind","keywords","Set","reservedWordsStrictSet","reservedWordsStrictBindSet","isReservedWord","word","inModule","isStrictReservedWord","has","isStrictBindOnlyReservedWord","isStrictBindReservedWord","isKeyword"],"sources":["../src/keyword.ts"],"sourcesContent":["const reservedWords = {\n keyword: [\n \"break\",\n \"case\",\n \"catch\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"do\",\n \"else\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"return\",\n \"switch\",\n \"throw\",\n \"try\",\n \"var\",\n \"const\",\n \"while\",\n \"with\",\n \"new\",\n \"this\",\n \"super\",\n \"class\",\n \"extends\",\n \"export\",\n \"import\",\n \"null\",\n \"true\",\n \"false\",\n \"in\",\n \"instanceof\",\n \"typeof\",\n \"void\",\n \"delete\",\n ],\n strict: [\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n \"yield\",\n ],\n strictBind: [\"eval\", \"arguments\"],\n};\nconst keywords = new Set(reservedWords.keyword);\nconst reservedWordsStrictSet = new Set(reservedWords.strict);\nconst reservedWordsStrictBindSet = new Set(reservedWords.strictBind);\n\n/**\n * Checks if word is a reserved word in non-strict mode\n */\nexport function isReservedWord(word: string, inModule: boolean): boolean {\n return (inModule && word === \"await\") || word === \"enum\";\n}\n\n/**\n * Checks if word is a reserved word in non-binding strict mode\n *\n * Includes non-strict reserved words\n */\nexport function isStrictReservedWord(word: string, inModule: boolean): boolean {\n return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode, but it is allowed as\n * a normal identifier.\n */\nexport function isStrictBindOnlyReservedWord(word: string): boolean {\n return reservedWordsStrictBindSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode\n *\n * Includes non-strict reserved words and non-binding strict reserved words\n */\nexport function isStrictBindReservedWord(\n word: string,\n inModule: boolean,\n): boolean {\n return (\n isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word)\n );\n}\n\nexport function isKeyword(word: string): boolean {\n return keywords.has(word);\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAMA,aAAa,GAAG;EACpBC,OAAO,EAAE,CACP,OADO,EAEP,MAFO,EAGP,OAHO,EAIP,UAJO,EAKP,UALO,EAMP,SANO,EAOP,IAPO,EAQP,MARO,EASP,SATO,EAUP,KAVO,EAWP,UAXO,EAYP,IAZO,EAaP,QAbO,EAcP,QAdO,EAeP,OAfO,EAgBP,KAhBO,EAiBP,KAjBO,EAkBP,OAlBO,EAmBP,OAnBO,EAoBP,MApBO,EAqBP,KArBO,EAsBP,MAtBO,EAuBP,OAvBO,EAwBP,OAxBO,EAyBP,SAzBO,EA0BP,QA1BO,EA2BP,QA3BO,EA4BP,MA5BO,EA6BP,MA7BO,EA8BP,OA9BO,EA+BP,IA/BO,EAgCP,YAhCO,EAiCP,QAjCO,EAkCP,MAlCO,EAmCP,QAnCO,CADW;EAsCpBC,MAAM,EAAE,CACN,YADM,EAEN,WAFM,EAGN,KAHM,EAIN,SAJM,EAKN,SALM,EAMN,WANM,EAON,QAPM,EAQN,QARM,EASN,OATM,CAtCY;EAiDpBC,UAAU,EAAE,CAAC,MAAD,EAAS,WAAT;AAjDQ,CAAtB;AAmDA,MAAMC,QAAQ,GAAG,IAAIC,GAAJ,CAAQL,aAAa,CAACC,OAAtB,CAAjB;AACA,MAAMK,sBAAsB,GAAG,IAAID,GAAJ,CAAQL,aAAa,CAACE,MAAtB,CAA/B;AACA,MAAMK,0BAA0B,GAAG,IAAIF,GAAJ,CAAQL,aAAa,CAACG,UAAtB,CAAnC;;AAKO,SAASK,cAAT,CAAwBC,IAAxB,EAAsCC,QAAtC,EAAkE;EACvE,OAAQA,QAAQ,IAAID,IAAI,KAAK,OAAtB,IAAkCA,IAAI,KAAK,MAAlD;AACD;;AAOM,SAASE,oBAAT,CAA8BF,IAA9B,EAA4CC,QAA5C,EAAwE;EAC7E,OAAOF,cAAc,CAACC,IAAD,EAAOC,QAAP,CAAd,IAAkCJ,sBAAsB,CAACM,GAAvB,CAA2BH,IAA3B,CAAzC;AACD;;AAMM,SAASI,4BAAT,CAAsCJ,IAAtC,EAA6D;EAClE,OAAOF,0BAA0B,CAACK,GAA3B,CAA+BH,IAA/B,CAAP;AACD;;AAOM,SAASK,wBAAT,CACLL,IADK,EAELC,QAFK,EAGI;EACT,OACEC,oBAAoB,CAACF,IAAD,EAAOC,QAAP,CAApB,IAAwCG,4BAA4B,CAACJ,IAAD,CADtE;AAGD;;AAEM,SAASM,SAAT,CAAmBN,IAAnB,EAA0C;EAC/C,OAAOL,QAAQ,CAACQ,GAAT,CAAaH,IAAb,CAAP;AACD"} |
|||
{"version":3,"names":["reservedWords","keyword","strict","strictBind","keywords","Set","reservedWordsStrictSet","reservedWordsStrictBindSet","isReservedWord","word","inModule","isStrictReservedWord","has","isStrictBindOnlyReservedWord","isStrictBindReservedWord","isKeyword"],"sources":["../src/keyword.ts"],"sourcesContent":["const reservedWords = {\n keyword: [\n \"break\",\n \"case\",\n \"catch\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"do\",\n \"else\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"return\",\n \"switch\",\n \"throw\",\n \"try\",\n \"var\",\n \"const\",\n \"while\",\n \"with\",\n \"new\",\n \"this\",\n \"super\",\n \"class\",\n \"extends\",\n \"export\",\n \"import\",\n \"null\",\n \"true\",\n \"false\",\n \"in\",\n \"instanceof\",\n \"typeof\",\n \"void\",\n \"delete\",\n ],\n strict: [\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n \"yield\",\n ],\n strictBind: [\"eval\", \"arguments\"],\n};\nconst keywords = new Set(reservedWords.keyword);\nconst reservedWordsStrictSet = new Set(reservedWords.strict);\nconst reservedWordsStrictBindSet = new Set(reservedWords.strictBind);\n\n/**\n * Checks if word is a reserved word in non-strict mode\n */\nexport function isReservedWord(word: string, inModule: boolean): boolean {\n return (inModule && word === \"await\") || word === \"enum\";\n}\n\n/**\n * Checks if word is a reserved word in non-binding strict mode\n *\n * Includes non-strict reserved words\n */\nexport function isStrictReservedWord(word: string, inModule: boolean): boolean {\n return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode, but it is allowed as\n * a normal identifier.\n */\nexport function isStrictBindOnlyReservedWord(word: string): boolean {\n return reservedWordsStrictBindSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode\n *\n * Includes non-strict reserved words and non-binding strict reserved words\n */\nexport function isStrictBindReservedWord(\n word: string,\n inModule: boolean,\n): boolean {\n return (\n isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word)\n );\n}\n\nexport function isKeyword(word: string): boolean {\n return keywords.has(word);\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAMA,aAAa,GAAG;EACpBC,OAAO,EAAE,CACP,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,QAAQ,CACT;EACDC,MAAM,EAAE,CACN,YAAY,EACZ,WAAW,EACX,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,OAAO,CACR;EACDC,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW;AAClC,CAAC;AACD,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAACL,aAAa,CAACC,OAAO,CAAC;AAC/C,MAAMK,sBAAsB,GAAG,IAAID,GAAG,CAACL,aAAa,CAACE,MAAM,CAAC;AAC5D,MAAMK,0BAA0B,GAAG,IAAIF,GAAG,CAACL,aAAa,CAACG,UAAU,CAAC;AAK7D,SAASK,cAAcA,CAACC,IAAY,EAAEC,QAAiB,EAAW;EACvE,OAAQA,QAAQ,IAAID,IAAI,KAAK,OAAO,IAAKA,IAAI,KAAK,MAAM;AAC1D;AAOO,SAASE,oBAAoBA,CAACF,IAAY,EAAEC,QAAiB,EAAW;EAC7E,OAAOF,cAAc,CAACC,IAAI,EAAEC,QAAQ,CAAC,IAAIJ,sBAAsB,CAACM,GAAG,CAACH,IAAI,CAAC;AAC3E;AAMO,SAASI,4BAA4BA,CAACJ,IAAY,EAAW;EAClE,OAAOF,0BAA0B,CAACK,GAAG,CAACH,IAAI,CAAC;AAC7C;AAOO,SAASK,wBAAwBA,CACtCL,IAAY,EACZC,QAAiB,EACR;EACT,OACEC,oBAAoB,CAACF,IAAI,EAAEC,QAAQ,CAAC,IAAIG,4BAA4B,CAACJ,IAAI,CAAC;AAE9E;AAEO,SAASM,SAASA,CAACN,IAAY,EAAW;EAC/C,OAAOL,QAAQ,CAACQ,GAAG,CAACH,IAAI,CAAC;AAC3B"} |
|||
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,40 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.defaultOptions = void 0; |
|||
exports.getOptions = getOptions; |
|||
const defaultOptions = { |
|||
sourceType: "script", |
|||
sourceFilename: undefined, |
|||
startColumn: 0, |
|||
startLine: 1, |
|||
allowAwaitOutsideFunction: false, |
|||
allowReturnOutsideFunction: false, |
|||
allowNewTargetOutsideFunction: false, |
|||
allowImportExportEverywhere: false, |
|||
allowSuperOutsideMethod: false, |
|||
allowUndeclaredExports: false, |
|||
plugins: [], |
|||
strictMode: null, |
|||
ranges: false, |
|||
tokens: false, |
|||
createParenthesizedExpressions: false, |
|||
errorRecovery: false, |
|||
attachComment: true, |
|||
annexB: true |
|||
}; |
|||
exports.defaultOptions = defaultOptions; |
|||
function getOptions(opts) { |
|||
if (opts && opts.annexB != null && opts.annexB !== false) { |
|||
throw new Error("The `annexB` option can only be set to `false`."); |
|||
} |
|||
const options = {}; |
|||
for (const key of Object.keys(defaultOptions)) { |
|||
options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key]; |
|||
} |
|||
return options; |
|||
} |
|||
|
|||
//# sourceMappingURL=options.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,106 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
var _exportNames = { |
|||
ParseErrorEnum: true, |
|||
Errors: true |
|||
}; |
|||
exports.Errors = void 0; |
|||
exports.ParseErrorEnum = ParseErrorEnum; |
|||
var _location = require("./util/location"); |
|||
var _credentials = require("./parse-error/credentials"); |
|||
Object.keys(_credentials).forEach(function (key) { |
|||
if (key === "default" || key === "__esModule") return; |
|||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; |
|||
if (key in exports && exports[key] === _credentials[key]) return; |
|||
Object.defineProperty(exports, key, { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _credentials[key]; |
|||
} |
|||
}); |
|||
}); |
|||
var _moduleErrors = require("./parse-error/module-errors"); |
|||
var _standardErrors = require("./parse-error/standard-errors"); |
|||
var _strictModeErrors = require("./parse-error/strict-mode-errors"); |
|||
var _pipelineOperatorErrors = require("./parse-error/pipeline-operator-errors"); |
|||
const _excluded = ["toMessage"], |
|||
_excluded2 = ["message"]; |
|||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } |
|||
function toParseErrorConstructor(_ref) { |
|||
let { |
|||
toMessage |
|||
} = _ref, |
|||
properties = _objectWithoutPropertiesLoose(_ref, _excluded); |
|||
return function constructor({ |
|||
loc, |
|||
details |
|||
}) { |
|||
return (0, _credentials.instantiate)(SyntaxError, Object.assign({}, properties, { |
|||
loc |
|||
}), { |
|||
clone(overrides = {}) { |
|||
const loc = overrides.loc || {}; |
|||
return constructor({ |
|||
loc: new _location.Position("line" in loc ? loc.line : this.loc.line, "column" in loc ? loc.column : this.loc.column, "index" in loc ? loc.index : this.loc.index), |
|||
details: Object.assign({}, this.details, overrides.details) |
|||
}); |
|||
}, |
|||
details: { |
|||
value: details, |
|||
enumerable: false |
|||
}, |
|||
message: { |
|||
get() { |
|||
return `${toMessage(this.details)} (${this.loc.line}:${this.loc.column})`; |
|||
}, |
|||
set(value) { |
|||
Object.defineProperty(this, "message", { |
|||
value |
|||
}); |
|||
} |
|||
}, |
|||
pos: { |
|||
reflect: "loc.index", |
|||
enumerable: true |
|||
}, |
|||
missingPlugin: "missingPlugin" in details && { |
|||
reflect: "details.missingPlugin", |
|||
enumerable: true |
|||
} |
|||
}); |
|||
}; |
|||
} |
|||
function ParseErrorEnum(argument, syntaxPlugin) { |
|||
if (Array.isArray(argument)) { |
|||
return parseErrorTemplates => ParseErrorEnum(parseErrorTemplates, argument[0]); |
|||
} |
|||
const ParseErrorConstructors = {}; |
|||
for (const reasonCode of Object.keys(argument)) { |
|||
const template = argument[reasonCode]; |
|||
const _ref2 = typeof template === "string" ? { |
|||
message: () => template |
|||
} : typeof template === "function" ? { |
|||
message: template |
|||
} : template, |
|||
{ |
|||
message |
|||
} = _ref2, |
|||
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2); |
|||
const toMessage = typeof message === "string" ? () => message : message; |
|||
ParseErrorConstructors[reasonCode] = toParseErrorConstructor(Object.assign({ |
|||
code: _credentials.ParseErrorCode.SyntaxError, |
|||
reasonCode, |
|||
toMessage |
|||
}, syntaxPlugin ? { |
|||
syntaxPlugin |
|||
} : {}, rest)); |
|||
} |
|||
return ParseErrorConstructors; |
|||
} |
|||
const Errors = Object.assign({}, ParseErrorEnum(_moduleErrors.default), ParseErrorEnum(_standardErrors.default), ParseErrorEnum(_strictModeErrors.default), ParseErrorEnum`pipelineOperator`(_pipelineOperatorErrors.default)); |
|||
exports.Errors = Errors; |
|||
|
|||
//# sourceMappingURL=parse-error.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,28 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.instantiate = exports.ParseErrorCode = void 0; |
|||
var ParseErrorCode = { |
|||
SyntaxError: "BABEL_PARSER_SYNTAX_ERROR", |
|||
SourceTypeModuleError: "BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED" |
|||
}; |
|||
exports.ParseErrorCode = ParseErrorCode; |
|||
const reflect = (keys, last = keys.length - 1) => ({ |
|||
get() { |
|||
return keys.reduce((object, key) => object[key], this); |
|||
}, |
|||
set(value) { |
|||
keys.reduce((item, key, i) => i === last ? item[key] = value : item[key], this); |
|||
} |
|||
}); |
|||
const instantiate = (constructor, properties, descriptors) => Object.keys(descriptors).map(key => [key, descriptors[key]]).filter(([, descriptor]) => !!descriptor).map(([key, descriptor]) => [key, typeof descriptor === "function" ? { |
|||
value: descriptor, |
|||
enumerable: false |
|||
} : typeof descriptor.reflect === "string" ? Object.assign({}, descriptor, reflect(descriptor.reflect.split("."))) : descriptor]).reduce((instance, [key, descriptor]) => Object.defineProperty(instance, key, Object.assign({ |
|||
configurable: true |
|||
}, descriptor)), Object.assign(new constructor(), properties)); |
|||
exports.instantiate = instantiate; |
|||
|
|||
//# sourceMappingURL=credentials.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["ParseErrorCode","SyntaxError","SourceTypeModuleError","exports","reflect","keys","last","length","get","reduce","object","key","set","value","item","i","instantiate","constructor","properties","descriptors","Object","map","filter","descriptor","enumerable","assign","split","instance","defineProperty","configurable"],"sources":["../../src/parse-error/credentials.ts"],"sourcesContent":["export const enum ParseErrorCode {\n SyntaxError = \"BABEL_PARSER_SYNTAX_ERROR\",\n SourceTypeModuleError = \"BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED\",\n}\n\nexport type SyntaxPlugin =\n | \"flow\"\n | \"typescript\"\n | \"jsx\"\n | \"pipelineOperator\"\n | \"placeholders\";\n\nexport type ToMessage<ErrorDetails> = (self: ErrorDetails) => string;\n\nexport type ParseErrorCredentials<ErrorDetails> = {\n code: ParseErrorCode;\n reasonCode: string;\n syntaxPlugin?: SyntaxPlugin;\n toMessage: ToMessage<ErrorDetails>;\n};\n\nconst reflect = (keys: string[], last = keys.length - 1) => ({\n get(this: unknown): unknown {\n return keys.reduce(\n (object, key) =>\n // @ts-expect-error key should index object\n object[key],\n this,\n );\n },\n set(this: unknown, value: unknown) {\n keys.reduce(\n // @ts-expect-error key should index item\n (item, key, i) => (i === last ? (item[key] = value) : item[key]),\n this,\n );\n },\n});\n\nconst instantiate = <T>(\n constructor: new () => T,\n properties: any,\n descriptors: any,\n) =>\n Object.keys(descriptors)\n .map(key => [key, descriptors[key]])\n .filter(([, descriptor]) => !!descriptor)\n .map(([key, descriptor]) => [\n key,\n typeof descriptor === \"function\"\n ? { value: descriptor, enumerable: false }\n : typeof descriptor.reflect === \"string\"\n ? { ...descriptor, ...reflect(descriptor.reflect.split(\".\")) }\n : descriptor,\n ])\n .reduce(\n (instance, [key, descriptor]) =>\n Object.defineProperty(instance, key, {\n configurable: true,\n ...descriptor,\n }),\n Object.assign(new constructor(), properties),\n );\n\nexport { instantiate };\n"],"mappings":";;;;;;IAAkBA,cAAc;EAAAC,WAAA;EAAAC,qBAAA;AAAA;AAAAC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAqBhC,MAAMI,OAAO,GAAGA,CAACC,IAAc,EAAEC,IAAI,GAAGD,IAAI,CAACE,MAAM,GAAG,CAAC,MAAM;EAC3DC,GAAGA,CAAA,EAAyB;IAC1B,OAAOH,IAAI,CAACI,MAAM,CAChB,CAACC,MAAM,EAAEC,GAAG,KAEVD,MAAM,CAACC,GAAG,CAAC,EACb,IAAI,CACL;EACH,CAAC;EACDC,GAAGA,CAAgBC,KAAc,EAAE;IACjCR,IAAI,CAACI,MAAM,CAET,CAACK,IAAI,EAAEH,GAAG,EAAEI,CAAC,KAAMA,CAAC,KAAKT,IAAI,GAAIQ,IAAI,CAACH,GAAG,CAAC,GAAGE,KAAK,GAAIC,IAAI,CAACH,GAAG,CAAE,EAChE,IAAI,CACL;EACH;AACF,CAAC,CAAC;AAEF,MAAMK,WAAW,GAAGA,CAClBC,WAAwB,EACxBC,UAAe,EACfC,WAAgB,KAEhBC,MAAM,CAACf,IAAI,CAACc,WAAW,CAAC,CACrBE,GAAG,CAACV,GAAG,IAAI,CAACA,GAAG,EAAEQ,WAAW,CAACR,GAAG,CAAC,CAAC,CAAC,CACnCW,MAAM,CAAC,CAAC,GAAGC,UAAU,CAAC,KAAK,CAAC,CAACA,UAAU,CAAC,CACxCF,GAAG,CAAC,CAAC,CAACV,GAAG,EAAEY,UAAU,CAAC,KAAK,CAC1BZ,GAAG,EACH,OAAOY,UAAU,KAAK,UAAU,GAC5B;EAAEV,KAAK,EAAEU,UAAU;EAAEC,UAAU,EAAE;AAAM,CAAC,GACxC,OAAOD,UAAU,CAACnB,OAAO,KAAK,QAAQ,GAAAgB,MAAA,CAAAK,MAAA,KACjCF,UAAU,EAAKnB,OAAO,CAACmB,UAAU,CAACnB,OAAO,CAACsB,KAAK,CAAC,GAAG,CAAC,CAAC,IAC1DH,UAAU,CACf,CAAC,CACDd,MAAM,CACL,CAACkB,QAAQ,EAAE,CAAChB,GAAG,EAAEY,UAAU,CAAC,KAC1BH,MAAM,CAACQ,cAAc,CAACD,QAAQ,EAAEhB,GAAG,EAAAS,MAAA,CAAAK,MAAA;EACjCI,YAAY,EAAE;AAAI,GACfN,UAAU,EACb,EACJH,MAAM,CAACK,MAAM,CAAC,IAAIR,WAAW,EAAE,EAAEC,UAAU,CAAC,CAC7C;AAACf,OAAA,CAAAa,WAAA,GAAAA,WAAA"} |
|||
@ -1,20 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _parseError = require("../parse-error"); |
|||
var _default = { |
|||
ImportMetaOutsideModule: { |
|||
message: `import.meta may appear only with 'sourceType: "module"'`, |
|||
code: _parseError.ParseErrorCode.SourceTypeModuleError |
|||
}, |
|||
ImportOutsideModule: { |
|||
message: `'import' and 'export' may appear only with 'sourceType: "module"'`, |
|||
code: _parseError.ParseErrorCode.SourceTypeModuleError |
|||
} |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=module-errors.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_parseError","require","_default","ImportMetaOutsideModule","message","code","ParseErrorCode","SourceTypeModuleError","ImportOutsideModule","exports","default"],"sources":["../../src/parse-error/module-errors.ts"],"sourcesContent":["import { ParseErrorCode } from \"../parse-error\";\n\nexport default {\n ImportMetaOutsideModule: {\n message: `import.meta may appear only with 'sourceType: \"module\"'`,\n code: ParseErrorCode.SourceTypeModuleError,\n },\n ImportOutsideModule: {\n message: `'import' and 'export' may appear only with 'sourceType: \"module\"'`,\n code: ParseErrorCode.SourceTypeModuleError,\n },\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAgD,IAAAC,QAAA,GAEjC;EACbC,uBAAuB,EAAE;IACvBC,OAAO,EAAG,yDAAwD;IAClEC,IAAI,EAAEC,0BAAc,CAACC;EACvB,CAAC;EACDC,mBAAmB,EAAE;IACnBJ,OAAO,EAAG,mEAAkE;IAC5EC,IAAI,EAAEC,0BAAc,CAACC;EACvB;AACF,CAAC;AAAAE,OAAA,CAAAC,OAAA,GAAAR,QAAA"} |
|||
@ -1,32 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.UnparenthesizedPipeBodyDescriptions = void 0; |
|||
var _toNodeDescription = require("./to-node-description"); |
|||
const UnparenthesizedPipeBodyDescriptions = new Set(["ArrowFunctionExpression", "AssignmentExpression", "ConditionalExpression", "YieldExpression"]); |
|||
exports.UnparenthesizedPipeBodyDescriptions = UnparenthesizedPipeBodyDescriptions; |
|||
var _default = { |
|||
PipeBodyIsTighter: "Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.", |
|||
PipeTopicRequiresHackPipes: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.', |
|||
PipeTopicUnbound: "Topic reference is unbound; it must be inside a pipe body.", |
|||
PipeTopicUnconfiguredToken: ({ |
|||
token |
|||
}) => `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { "proposal": "hack", "topicToken": "${token}" }.`, |
|||
PipeTopicUnused: "Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.", |
|||
PipeUnparenthesizedBody: ({ |
|||
type |
|||
}) => `Hack-style pipe body cannot be an unparenthesized ${(0, _toNodeDescription.default)({ |
|||
type |
|||
})}; please wrap it in parentheses.`,
|
|||
PipelineBodyNoArrow: 'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.', |
|||
PipelineBodySequenceExpression: "Pipeline body may not be a comma-separated sequence expression.", |
|||
PipelineHeadSequenceExpression: "Pipeline head should not be a comma-separated sequence expression.", |
|||
PipelineTopicUnused: "Pipeline is in topic style but does not use topic reference.", |
|||
PrimaryTopicNotAllowed: "Topic reference was used in a lexical context without topic binding.", |
|||
PrimaryTopicRequiresSmartPipeline: 'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.' |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=pipeline-operator-errors.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_toNodeDescription","require","UnparenthesizedPipeBodyDescriptions","Set","exports","_default","PipeBodyIsTighter","PipeTopicRequiresHackPipes","PipeTopicUnbound","PipeTopicUnconfiguredToken","token","PipeTopicUnused","PipeUnparenthesizedBody","type","toNodeDescription","PipelineBodyNoArrow","PipelineBodySequenceExpression","PipelineHeadSequenceExpression","PipelineTopicUnused","PrimaryTopicNotAllowed","PrimaryTopicRequiresSmartPipeline","default"],"sources":["../../src/parse-error/pipeline-operator-errors.ts"],"sourcesContent":["import toNodeDescription from \"./to-node-description\";\n\nexport const UnparenthesizedPipeBodyDescriptions = new Set([\n \"ArrowFunctionExpression\",\n \"AssignmentExpression\",\n \"ConditionalExpression\",\n \"YieldExpression\",\n] as const);\n\ntype GetSetMemberType<T extends Set<any>> = T extends Set<infer M>\n ? M\n : unknown;\n\ntype UnparenthesizedPipeBodyTypes = GetSetMemberType<\n typeof UnparenthesizedPipeBodyDescriptions\n>;\n\nexport default {\n // This error is only used by the smart-mix proposal\n PipeBodyIsTighter:\n \"Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.\",\n PipeTopicRequiresHackPipes:\n 'Topic reference is used, but the pipelineOperator plugin was not passed a \"proposal\": \"hack\" or \"smart\" option.',\n PipeTopicUnbound:\n \"Topic reference is unbound; it must be inside a pipe body.\",\n PipeTopicUnconfiguredToken: ({ token }: { token: string }) =>\n `Invalid topic token ${token}. In order to use ${token} as a topic reference, the pipelineOperator plugin must be configured with { \"proposal\": \"hack\", \"topicToken\": \"${token}\" }.`,\n PipeTopicUnused:\n \"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.\",\n PipeUnparenthesizedBody: ({ type }: { type: UnparenthesizedPipeBodyTypes }) =>\n `Hack-style pipe body cannot be an unparenthesized ${toNodeDescription({\n type,\n })}; please wrap it in parentheses.`,\n\n // Messages whose codes start with “Pipeline” or “PrimaryTopic”\n // are retained for backwards compatibility\n // with the deprecated smart-mix pipe operator proposal plugin.\n // They are subject to removal in a future major version.\n PipelineBodyNoArrow:\n 'Unexpected arrow \"=>\" after pipeline body; arrow function in pipeline body must be parenthesized.',\n PipelineBodySequenceExpression:\n \"Pipeline body may not be a comma-separated sequence expression.\",\n PipelineHeadSequenceExpression:\n \"Pipeline head should not be a comma-separated sequence expression.\",\n PipelineTopicUnused:\n \"Pipeline is in topic style but does not use topic reference.\",\n PrimaryTopicNotAllowed:\n \"Topic reference was used in a lexical context without topic binding.\",\n PrimaryTopicRequiresSmartPipeline:\n 'Topic reference is used, but the pipelineOperator plugin was not passed a \"proposal\": \"hack\" or \"smart\" option.',\n};\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAEO,MAAMC,mCAAmC,GAAG,IAAIC,GAAG,CAAC,CACzD,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,CAClB,CAAU;AAACC,OAAA,CAAAF,mCAAA,GAAAA,mCAAA;AAAA,IAAAG,QAAA,GAUG;EAEbC,iBAAiB,EACf,uJAAuJ;EACzJC,0BAA0B,EACxB,iHAAiH;EACnHC,gBAAgB,EACd,4DAA4D;EAC9DC,0BAA0B,EAAEA,CAAC;IAAEC;EAAyB,CAAC,KACtD,uBAAsBA,KAAM,qBAAoBA,KAAM,mHAAkHA,KAAM,MAAK;EACtLC,eAAe,EACb,yGAAyG;EAC3GC,uBAAuB,EAAEA,CAAC;IAAEC;EAA6C,CAAC,KACvE,qDAAoD,IAAAC,0BAAiB,EAAC;IACrED;EACF,CAAC,CAAE,kCAAiC;EAMtCE,mBAAmB,EACjB,mGAAmG;EACrGC,8BAA8B,EAC5B,iEAAiE;EACnEC,8BAA8B,EAC5B,oEAAoE;EACtEC,mBAAmB,EACjB,8DAA8D;EAChEC,sBAAsB,EACpB,sEAAsE;EACxEC,iCAAiC,EAC/B;AACJ,CAAC;AAAAhB,OAAA,CAAAiB,OAAA,GAAAhB,QAAA"} |
|||
@ -1,218 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _toNodeDescription = require("./to-node-description"); |
|||
var _default = { |
|||
AccessorIsGenerator: ({ |
|||
kind |
|||
}) => `A ${kind}ter cannot be a generator.`, |
|||
ArgumentsInClass: "'arguments' is only allowed in functions and class methods.", |
|||
AsyncFunctionInSingleStatementContext: "Async functions can only be declared at the top level or inside a block.", |
|||
AwaitBindingIdentifier: "Can not use 'await' as identifier inside an async function.", |
|||
AwaitBindingIdentifierInStaticBlock: "Can not use 'await' as identifier inside a static block.", |
|||
AwaitExpressionFormalParameter: "'await' is not allowed in async function parameters.", |
|||
AwaitNotInAsyncContext: "'await' is only allowed within async functions and at the top levels of modules.", |
|||
AwaitNotInAsyncFunction: "'await' is only allowed within async functions.", |
|||
BadGetterArity: "A 'get' accessor must not have any formal parameters.", |
|||
BadSetterArity: "A 'set' accessor must have exactly one formal parameter.", |
|||
BadSetterRestParameter: "A 'set' accessor function argument must not be a rest parameter.", |
|||
ConstructorClassField: "Classes may not have a field named 'constructor'.", |
|||
ConstructorClassPrivateField: "Classes may not have a private field named '#constructor'.", |
|||
ConstructorIsAccessor: "Class constructor may not be an accessor.", |
|||
ConstructorIsAsync: "Constructor can't be an async function.", |
|||
ConstructorIsGenerator: "Constructor can't be a generator.", |
|||
DeclarationMissingInitializer: ({ |
|||
kind |
|||
}) => `Missing initializer in ${kind} declaration.`, |
|||
DecoratorArgumentsOutsideParentheses: "Decorator arguments must be moved inside parentheses: use '@(decorator(args))' instead of '@(decorator)(args)'.", |
|||
DecoratorBeforeExport: "Decorators must be placed *before* the 'export' keyword. Remove the 'decoratorsBeforeExport: true' option to use the 'export @decorator class {}' syntax.", |
|||
DecoratorsBeforeAfterExport: "Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time.", |
|||
DecoratorConstructor: "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?", |
|||
DecoratorExportClass: "Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.", |
|||
DecoratorSemicolon: "Decorators must not be followed by a semicolon.", |
|||
DecoratorStaticBlock: "Decorators can't be used with a static block.", |
|||
DeletePrivateField: "Deleting a private field is not allowed.", |
|||
DestructureNamedImport: "ES2015 named imports do not destructure. Use another statement for destructuring after the import.", |
|||
DuplicateConstructor: "Duplicate constructor in the same class.", |
|||
DuplicateDefaultExport: "Only one default export allowed per module.", |
|||
DuplicateExport: ({ |
|||
exportName |
|||
}) => `\`${exportName}\` has already been exported. Exported identifiers must be unique.`, |
|||
DuplicateProto: "Redefinition of __proto__ property.", |
|||
DuplicateRegExpFlags: "Duplicate regular expression flag.", |
|||
ElementAfterRest: "Rest element must be last element.", |
|||
EscapedCharNotAnIdentifier: "Invalid Unicode escape.", |
|||
ExportBindingIsString: ({ |
|||
localName, |
|||
exportName |
|||
}) => `A string literal cannot be used as an exported binding without \`from\`.\n- Did you mean \`export { '${localName}' as '${exportName}' } from 'some-module'\`?`, |
|||
ExportDefaultFromAsIdentifier: "'from' is not allowed as an identifier after 'export default'.", |
|||
ForInOfLoopInitializer: ({ |
|||
type |
|||
}) => `'${type === "ForInStatement" ? "for-in" : "for-of"}' loop variable declaration may not have an initializer.`, |
|||
ForInUsing: "For-in loop may not start with 'using' declaration.", |
|||
ForOfAsync: "The left-hand side of a for-of loop may not be 'async'.", |
|||
ForOfLet: "The left-hand side of a for-of loop may not start with 'let'.", |
|||
GeneratorInSingleStatementContext: "Generators can only be declared at the top level or inside a block.", |
|||
IllegalBreakContinue: ({ |
|||
type |
|||
}) => `Unsyntactic ${type === "BreakStatement" ? "break" : "continue"}.`, |
|||
IllegalLanguageModeDirective: "Illegal 'use strict' directive in function with non-simple parameter list.", |
|||
IllegalReturn: "'return' outside of function.", |
|||
ImportBindingIsString: ({ |
|||
importName |
|||
}) => `A string literal cannot be used as an imported binding.\n- Did you mean \`import { "${importName}" as foo }\`?`, |
|||
ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments.", |
|||
ImportCallArity: ({ |
|||
maxArgumentCount |
|||
}) => `\`import()\` requires exactly ${maxArgumentCount === 1 ? "one argument" : "one or two arguments"}.`, |
|||
ImportCallNotNewExpression: "Cannot use new with import(...).", |
|||
ImportCallSpreadArgument: "`...` is not allowed in `import()`.", |
|||
ImportJSONBindingNotDefault: "A JSON module can only be imported with `default`.", |
|||
ImportReflectionHasAssertion: "`import module x` cannot have assertions.", |
|||
ImportReflectionNotBinding: 'Only `import module x from "./module"` is valid.', |
|||
IncompatibleRegExpUVFlags: "The 'u' and 'v' regular expression flags cannot be enabled at the same time.", |
|||
InvalidBigIntLiteral: "Invalid BigIntLiteral.", |
|||
InvalidCodePoint: "Code point out of bounds.", |
|||
InvalidCoverInitializedName: "Invalid shorthand property initializer.", |
|||
InvalidDecimal: "Invalid decimal.", |
|||
InvalidDigit: ({ |
|||
radix |
|||
}) => `Expected number in radix ${radix}.`, |
|||
InvalidEscapeSequence: "Bad character escape sequence.", |
|||
InvalidEscapeSequenceTemplate: "Invalid escape sequence in template.", |
|||
InvalidEscapedReservedWord: ({ |
|||
reservedWord |
|||
}) => `Escape sequence in keyword ${reservedWord}.`, |
|||
InvalidIdentifier: ({ |
|||
identifierName |
|||
}) => `Invalid identifier ${identifierName}.`, |
|||
InvalidLhs: ({ |
|||
ancestor |
|||
}) => `Invalid left-hand side in ${(0, _toNodeDescription.default)(ancestor)}.`, |
|||
InvalidLhsBinding: ({ |
|||
ancestor |
|||
}) => `Binding invalid left-hand side in ${(0, _toNodeDescription.default)(ancestor)}.`, |
|||
InvalidNumber: "Invalid number.", |
|||
InvalidOrMissingExponent: "Floating-point numbers require a valid exponent after the 'e'.", |
|||
InvalidOrUnexpectedToken: ({ |
|||
unexpected |
|||
}) => `Unexpected character '${unexpected}'.`, |
|||
InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern.", |
|||
InvalidPrivateFieldResolution: ({ |
|||
identifierName |
|||
}) => `Private name #${identifierName} is not defined.`, |
|||
InvalidPropertyBindingPattern: "Binding member expression.", |
|||
InvalidRecordProperty: "Only properties and spread elements are allowed in record definitions.", |
|||
InvalidRestAssignmentPattern: "Invalid rest operator's argument.", |
|||
LabelRedeclaration: ({ |
|||
labelName |
|||
}) => `Label '${labelName}' is already declared.`, |
|||
LetInLexicalBinding: "'let' is not allowed to be used as a name in 'let' or 'const' declarations.", |
|||
LineTerminatorBeforeArrow: "No line break is allowed before '=>'.", |
|||
MalformedRegExpFlags: "Invalid regular expression flag.", |
|||
MissingClassName: "A class name is required.", |
|||
MissingEqInAssignment: "Only '=' operator can be used for specifying default value.", |
|||
MissingSemicolon: "Missing semicolon.", |
|||
MissingPlugin: ({ |
|||
missingPlugin |
|||
}) => `This experimental syntax requires enabling the parser plugin: ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`, |
|||
MissingOneOfPlugins: ({ |
|||
missingPlugin |
|||
}) => `This experimental syntax requires enabling one of the following parser plugin(s): ${missingPlugin.map(name => JSON.stringify(name)).join(", ")}.`, |
|||
MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX.", |
|||
MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators.", |
|||
ModuleAttributeDifferentFromType: "The only accepted module attribute is `type`.", |
|||
ModuleAttributeInvalidValue: "Only string literals are allowed as module attribute values.", |
|||
ModuleAttributesWithDuplicateKeys: ({ |
|||
key |
|||
}) => `Duplicate key "${key}" is not allowed in module attributes.`, |
|||
ModuleExportNameHasLoneSurrogate: ({ |
|||
surrogateCharCode |
|||
}) => `An export name cannot include a lone surrogate, found '\\u${surrogateCharCode.toString(16)}'.`, |
|||
ModuleExportUndefined: ({ |
|||
localName |
|||
}) => `Export '${localName}' is not defined.`, |
|||
MultipleDefaultsInSwitch: "Multiple default clauses.", |
|||
NewlineAfterThrow: "Illegal newline after throw.", |
|||
NoCatchOrFinally: "Missing catch or finally clause.", |
|||
NumberIdentifier: "Identifier directly after number.", |
|||
NumericSeparatorInEscapeSequence: "Numeric separators are not allowed inside unicode escape sequences or hex escape sequences.", |
|||
ObsoleteAwaitStar: "'await*' has been removed from the async functions proposal. Use Promise.all() instead.", |
|||
OptionalChainingNoNew: "Constructors in/after an Optional Chain are not allowed.", |
|||
OptionalChainingNoTemplate: "Tagged Template Literals are not allowed in optionalChain.", |
|||
OverrideOnConstructor: "'override' modifier cannot appear on a constructor declaration.", |
|||
ParamDupe: "Argument name clash.", |
|||
PatternHasAccessor: "Object pattern can't contain getter or setter.", |
|||
PatternHasMethod: "Object pattern can't contain methods.", |
|||
PrivateInExpectedIn: ({ |
|||
identifierName |
|||
}) => `Private names are only allowed in property accesses (\`obj.#${identifierName}\`) or in \`in\` expressions (\`#${identifierName} in obj\`).`, |
|||
PrivateNameRedeclaration: ({ |
|||
identifierName |
|||
}) => `Duplicate private name #${identifierName}.`, |
|||
RecordExpressionBarIncorrectEndSyntaxType: "Record expressions ending with '|}' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.", |
|||
RecordExpressionBarIncorrectStartSyntaxType: "Record expressions starting with '{|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.", |
|||
RecordExpressionHashIncorrectStartSyntaxType: "Record expressions starting with '#{' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.", |
|||
RecordNoProto: "'__proto__' is not allowed in Record expressions.", |
|||
RestTrailingComma: "Unexpected trailing comma after rest element.", |
|||
SloppyFunction: "In non-strict mode code, functions can only be declared at top level or inside a block.", |
|||
SloppyFunctionAnnexB: "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement.", |
|||
StaticPrototype: "Classes may not have static property named prototype.", |
|||
SuperNotAllowed: "`super()` is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?", |
|||
SuperPrivateField: "Private fields can't be accessed on super.", |
|||
TrailingDecorator: "Decorators must be attached to a class element.", |
|||
TupleExpressionBarIncorrectEndSyntaxType: "Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.", |
|||
TupleExpressionBarIncorrectStartSyntaxType: "Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'.", |
|||
TupleExpressionHashIncorrectStartSyntaxType: "Tuple expressions starting with '#[' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'hash'.", |
|||
UnexpectedArgumentPlaceholder: "Unexpected argument placeholder.", |
|||
UnexpectedAwaitAfterPipelineBody: 'Unexpected "await" after pipeline body; await must have parentheses in minimal proposal.', |
|||
UnexpectedDigitAfterHash: "Unexpected digit after hash token.", |
|||
UnexpectedImportExport: "'import' and 'export' may only appear at the top level.", |
|||
UnexpectedKeyword: ({ |
|||
keyword |
|||
}) => `Unexpected keyword '${keyword}'.`, |
|||
UnexpectedLeadingDecorator: "Leading decorators must be attached to a class declaration.", |
|||
UnexpectedLexicalDeclaration: "Lexical declaration cannot appear in a single-statement context.", |
|||
UnexpectedNewTarget: "`new.target` can only be used in functions or class properties.", |
|||
UnexpectedNumericSeparator: "A numeric separator is only allowed between two digits.", |
|||
UnexpectedPrivateField: "Unexpected private name.", |
|||
UnexpectedReservedWord: ({ |
|||
reservedWord |
|||
}) => `Unexpected reserved word '${reservedWord}'.`, |
|||
UnexpectedSuper: "'super' is only allowed in object methods and classes.", |
|||
UnexpectedToken: ({ |
|||
expected, |
|||
unexpected |
|||
}) => `Unexpected token${unexpected ? ` '${unexpected}'.` : ""}${expected ? `, expected "${expected}"` : ""}`, |
|||
UnexpectedTokenUnaryExponentiation: "Illegal expression. Wrap left hand side or entire exponentiation in parentheses.", |
|||
UnexpectedUsingDeclaration: "Using declaration cannot appear in the top level when source type is `script`.", |
|||
UnsupportedBind: "Binding should be performed on object property.", |
|||
UnsupportedDecoratorExport: "A decorated export must export a class declaration.", |
|||
UnsupportedDefaultExport: "Only expressions, functions or classes are allowed as the `default` export.", |
|||
UnsupportedImport: "`import` can only be used in `import()` or `import.meta`.", |
|||
UnsupportedMetaProperty: ({ |
|||
target, |
|||
onlyValidPropertyName |
|||
}) => `The only valid meta property for ${target} is ${target}.${onlyValidPropertyName}.`, |
|||
UnsupportedParameterDecorator: "Decorators cannot be used to decorate parameters.", |
|||
UnsupportedPropertyDecorator: "Decorators cannot be used to decorate object literal properties.", |
|||
UnsupportedSuper: "'super' can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]).", |
|||
UnterminatedComment: "Unterminated comment.", |
|||
UnterminatedRegExp: "Unterminated regular expression.", |
|||
UnterminatedString: "Unterminated string constant.", |
|||
UnterminatedTemplate: "Unterminated template.", |
|||
UsingDeclarationHasBindingPattern: "Using declaration cannot have destructuring patterns.", |
|||
VarRedeclaration: ({ |
|||
identifierName |
|||
}) => `Identifier '${identifierName}' has already been declared.`, |
|||
YieldBindingIdentifier: "Can not use 'yield' as identifier inside a generator.", |
|||
YieldInParameter: "Yield expression is not allowed in formal parameters.", |
|||
ZeroDigitNumericSeparator: "Numeric separator can not be used after leading 0." |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=standard-errors.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,22 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _default = { |
|||
StrictDelete: "Deleting local variable in strict mode.", |
|||
StrictEvalArguments: ({ |
|||
referenceName |
|||
}) => `Assigning to '${referenceName}' in strict mode.`, |
|||
StrictEvalArgumentsBinding: ({ |
|||
bindingName |
|||
}) => `Binding '${bindingName}' in strict mode.`, |
|||
StrictFunction: "In strict mode code, functions can only be declared at top level or inside a block.", |
|||
StrictNumericEscape: "The only valid numeric escape in strict mode is '\\0'.", |
|||
StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode.", |
|||
StrictWith: "'with' in strict mode." |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=strict-mode-errors.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["StrictDelete","StrictEvalArguments","referenceName","StrictEvalArgumentsBinding","bindingName","StrictFunction","StrictNumericEscape","StrictOctalLiteral","StrictWith","exports","default","_default"],"sources":["../../src/parse-error/strict-mode-errors.ts"],"sourcesContent":["export default {\n StrictDelete: \"Deleting local variable in strict mode.\",\n\n // `referenceName` is the StringValue[1] of an IdentifierReference[2], which\n // is represented as just an `Identifier`[3] in the Babel AST.\n // 1. https://tc39.es/ecma262/#sec-static-semantics-stringvalue\n // 2. https://tc39.es/ecma262/#prod-IdentifierReference\n // 3. https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md#identifier\n StrictEvalArguments: ({ referenceName }: { referenceName: string }) =>\n `Assigning to '${referenceName}' in strict mode.`,\n\n // `bindingName` is the StringValue[1] of a BindingIdentifier[2], which is\n // represented as just an `Identifier`[3] in the Babel AST.\n // 1. https://tc39.es/ecma262/#sec-static-semantics-stringvalue\n // 2. https://tc39.es/ecma262/#prod-BindingIdentifier\n // 3. https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md#identifier\n StrictEvalArgumentsBinding: ({ bindingName }: { bindingName: string }) =>\n `Binding '${bindingName}' in strict mode.`,\n\n StrictFunction:\n \"In strict mode code, functions can only be declared at top level or inside a block.\",\n\n StrictNumericEscape: \"The only valid numeric escape in strict mode is '\\\\0'.\",\n\n StrictOctalLiteral: \"Legacy octal literals are not allowed in strict mode.\",\n\n StrictWith: \"'with' in strict mode.\",\n};\n"],"mappings":";;;;;;eAAe;EACbA,YAAY,EAAE,yCAAyC;EAOvDC,mBAAmB,EAAEA,CAAC;IAAEC;EAAyC,CAAC,KAC/D,iBAAgBA,aAAc,mBAAkB;EAOnDC,0BAA0B,EAAEA,CAAC;IAAEC;EAAqC,CAAC,KAClE,YAAWA,WAAY,mBAAkB;EAE5CC,cAAc,EACZ,qFAAqF;EAEvFC,mBAAmB,EAAE,wDAAwD;EAE7EC,kBAAkB,EAAE,uDAAuD;EAE3EC,UAAU,EAAE;AACd,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA"} |
|||
@ -1,39 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
const NodeDescriptions = { |
|||
ArrayPattern: "array destructuring pattern", |
|||
AssignmentExpression: "assignment expression", |
|||
AssignmentPattern: "assignment expression", |
|||
ArrowFunctionExpression: "arrow function expression", |
|||
ConditionalExpression: "conditional expression", |
|||
CatchClause: "catch clause", |
|||
ForOfStatement: "for-of statement", |
|||
ForInStatement: "for-in statement", |
|||
ForStatement: "for-loop", |
|||
FormalParameters: "function parameter list", |
|||
Identifier: "identifier", |
|||
ImportSpecifier: "import specifier", |
|||
ImportDefaultSpecifier: "import default specifier", |
|||
ImportNamespaceSpecifier: "import namespace specifier", |
|||
ObjectPattern: "object destructuring pattern", |
|||
ParenthesizedExpression: "parenthesized expression", |
|||
RestElement: "rest element", |
|||
UpdateExpression: { |
|||
true: "prefix operation", |
|||
false: "postfix operation" |
|||
}, |
|||
VariableDeclarator: "variable declaration", |
|||
YieldExpression: "yield expression" |
|||
}; |
|||
const toNodeDescription = ({ |
|||
type, |
|||
prefix |
|||
}) => type === "UpdateExpression" ? NodeDescriptions.UpdateExpression[String(prefix)] : NodeDescriptions[type]; |
|||
var _default = toNodeDescription; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=to-node-description.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["NodeDescriptions","ArrayPattern","AssignmentExpression","AssignmentPattern","ArrowFunctionExpression","ConditionalExpression","CatchClause","ForOfStatement","ForInStatement","ForStatement","FormalParameters","Identifier","ImportSpecifier","ImportDefaultSpecifier","ImportNamespaceSpecifier","ObjectPattern","ParenthesizedExpression","RestElement","UpdateExpression","true","false","VariableDeclarator","YieldExpression","toNodeDescription","type","prefix","String","_default","exports","default"],"sources":["../../src/parse-error/to-node-description.ts"],"sourcesContent":["const NodeDescriptions = {\n ArrayPattern: \"array destructuring pattern\",\n AssignmentExpression: \"assignment expression\",\n AssignmentPattern: \"assignment expression\",\n ArrowFunctionExpression: \"arrow function expression\",\n ConditionalExpression: \"conditional expression\",\n CatchClause: \"catch clause\",\n ForOfStatement: \"for-of statement\",\n ForInStatement: \"for-in statement\",\n ForStatement: \"for-loop\",\n FormalParameters: \"function parameter list\",\n Identifier: \"identifier\",\n ImportSpecifier: \"import specifier\",\n ImportDefaultSpecifier: \"import default specifier\",\n ImportNamespaceSpecifier: \"import namespace specifier\",\n ObjectPattern: \"object destructuring pattern\",\n ParenthesizedExpression: \"parenthesized expression\",\n RestElement: \"rest element\",\n UpdateExpression: {\n true: \"prefix operation\",\n false: \"postfix operation\",\n },\n VariableDeclarator: \"variable declaration\",\n YieldExpression: \"yield expression\",\n};\n\ntype NodeTypesWithDescriptions = keyof Omit<\n typeof NodeDescriptions,\n \"UpdateExpression\"\n>;\n\ntype NodeWithDescription =\n | {\n type: \"UpdateExpression\";\n prefix: boolean;\n }\n | {\n type: NodeTypesWithDescriptions;\n };\n\n// @ts-expect-error prefix is specified only when type is UpdateExpression\n// eslint-disable-next-line no-confusing-arrow\nconst toNodeDescription = ({ type, prefix }: NodeWithDescription) =>\n type === \"UpdateExpression\"\n ? NodeDescriptions.UpdateExpression[String(prefix) as \"true\" | \"false\"]\n : NodeDescriptions[type];\n\nexport default toNodeDescription;\n"],"mappings":";;;;;;AAAA,MAAMA,gBAAgB,GAAG;EACvBC,YAAY,EAAE,6BAA6B;EAC3CC,oBAAoB,EAAE,uBAAuB;EAC7CC,iBAAiB,EAAE,uBAAuB;EAC1CC,uBAAuB,EAAE,2BAA2B;EACpDC,qBAAqB,EAAE,wBAAwB;EAC/CC,WAAW,EAAE,cAAc;EAC3BC,cAAc,EAAE,kBAAkB;EAClCC,cAAc,EAAE,kBAAkB;EAClCC,YAAY,EAAE,UAAU;EACxBC,gBAAgB,EAAE,yBAAyB;EAC3CC,UAAU,EAAE,YAAY;EACxBC,eAAe,EAAE,kBAAkB;EACnCC,sBAAsB,EAAE,0BAA0B;EAClDC,wBAAwB,EAAE,4BAA4B;EACtDC,aAAa,EAAE,8BAA8B;EAC7CC,uBAAuB,EAAE,0BAA0B;EACnDC,WAAW,EAAE,cAAc;EAC3BC,gBAAgB,EAAE;IAChBC,IAAI,EAAE,kBAAkB;IACxBC,KAAK,EAAE;EACT,CAAC;EACDC,kBAAkB,EAAE,sBAAsB;EAC1CC,eAAe,EAAE;AACnB,CAAC;AAkBD,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC,IAAI;EAAEC;AAA4B,CAAC,KAC9DD,IAAI,KAAK,kBAAkB,GACvBxB,gBAAgB,CAACkB,gBAAgB,CAACQ,MAAM,CAACD,MAAM,CAAC,CAAqB,GACrEzB,gBAAgB,CAACwB,IAAI,CAAC;AAAC,IAAAG,QAAA,GAEdJ,iBAAiB;AAAAK,OAAA,CAAAC,OAAA,GAAAF,QAAA"} |
|||
@ -1,36 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
class BaseParser { |
|||
constructor() { |
|||
this.sawUnambiguousESM = false; |
|||
this.ambiguousScriptDifferentAst = false; |
|||
} |
|||
hasPlugin(pluginConfig) { |
|||
if (typeof pluginConfig === "string") { |
|||
return this.plugins.has(pluginConfig); |
|||
} else { |
|||
const [pluginName, pluginOptions] = pluginConfig; |
|||
if (!this.hasPlugin(pluginName)) { |
|||
return false; |
|||
} |
|||
const actualOptions = this.plugins.get(pluginName); |
|||
for (const key of Object.keys(pluginOptions)) { |
|||
if ((actualOptions == null ? void 0 : actualOptions[key]) !== pluginOptions[key]) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
getPluginOption(plugin, name) { |
|||
var _this$plugins$get; |
|||
return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name]; |
|||
} |
|||
} |
|||
exports.default = BaseParser; |
|||
|
|||
//# sourceMappingURL=base.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["BaseParser","constructor","sawUnambiguousESM","ambiguousScriptDifferentAst","hasPlugin","pluginConfig","plugins","has","pluginName","pluginOptions","actualOptions","get","key","Object","keys","getPluginOption","plugin","name","_this$plugins$get","exports","default"],"sources":["../../src/parser/base.ts"],"sourcesContent":["import type { Options } from \"../options\";\nimport type State from \"../tokenizer/state\";\nimport type { PluginsMap } from \"./index\";\nimport type ScopeHandler from \"../util/scope\";\nimport type ExpressionScopeHandler from \"../util/expression-scope\";\nimport type ClassScopeHandler from \"../util/class-scope\";\nimport type ProductionParameterHandler from \"../util/production-parameter\";\nimport type {\n ParserPluginWithOptions,\n PluginConfig,\n PluginOptions,\n} from \"../typings\";\n\nexport default class BaseParser {\n // Properties set by constructor in index.js\n declare options: Options;\n declare inModule: boolean;\n declare scope: ScopeHandler<any>;\n declare classScope: ClassScopeHandler;\n declare prodParam: ProductionParameterHandler;\n declare expressionScope: ExpressionScopeHandler;\n declare plugins: PluginsMap;\n declare filename: string | undefined | null;\n // Names of exports store. `default` is stored as a name for both\n // `export default foo;` and `export { foo as default };`.\n declare exportedIdentifiers: Set<string>;\n sawUnambiguousESM: boolean = false;\n ambiguousScriptDifferentAst: boolean = false;\n\n // Initialized by Tokenizer\n declare state: State;\n // input and length are not in state as they are constant and we do\n // not want to ever copy them, which happens if state gets cloned\n declare input: string;\n declare length: number;\n\n // This method accepts either a string (plugin name) or an array pair\n // (plugin name and options object). If an options object is given,\n // then each value is non-recursively checked for identity with that\n // plugin’s actual option value.\n hasPlugin(pluginConfig: PluginConfig): boolean {\n if (typeof pluginConfig === \"string\") {\n return this.plugins.has(pluginConfig);\n } else {\n const [pluginName, pluginOptions] = pluginConfig;\n if (!this.hasPlugin(pluginName)) {\n return false;\n }\n const actualOptions = this.plugins.get(pluginName);\n for (const key of Object.keys(\n pluginOptions,\n ) as (keyof typeof pluginOptions)[]) {\n if (actualOptions?.[key] !== pluginOptions[key]) {\n return false;\n }\n }\n return true;\n }\n }\n\n getPluginOption<\n PluginName extends ParserPluginWithOptions[0],\n OptionName extends keyof PluginOptions<PluginName>,\n >(plugin: PluginName, name: OptionName) {\n return (this.plugins.get(plugin) as null | PluginOptions<PluginName>)?.[\n name\n ];\n }\n}\n"],"mappings":";;;;;;AAae,MAAMA,UAAU,CAAC;EAAAC,YAAA;IAAA,KAa9BC,iBAAiB,GAAY,KAAK;IAAA,KAClCC,2BAA2B,GAAY,KAAK;EAAA;EAa5CC,SAASA,CAACC,YAA0B,EAAW;IAC7C,IAAI,OAAOA,YAAY,KAAK,QAAQ,EAAE;MACpC,OAAO,IAAI,CAACC,OAAO,CAACC,GAAG,CAACF,YAAY,CAAC;IACvC,CAAC,MAAM;MACL,MAAM,CAACG,UAAU,EAAEC,aAAa,CAAC,GAAGJ,YAAY;MAChD,IAAI,CAAC,IAAI,CAACD,SAAS,CAACI,UAAU,CAAC,EAAE;QAC/B,OAAO,KAAK;MACd;MACA,MAAME,aAAa,GAAG,IAAI,CAACJ,OAAO,CAACK,GAAG,CAACH,UAAU,CAAC;MAClD,KAAK,MAAMI,GAAG,IAAIC,MAAM,CAACC,IAAI,CAC3BL,aAAa,CACd,EAAoC;QACnC,IAAI,CAAAC,aAAa,oBAAbA,aAAa,CAAGE,GAAG,CAAC,MAAKH,aAAa,CAACG,GAAG,CAAC,EAAE;UAC/C,OAAO,KAAK;QACd;MACF;MACA,OAAO,IAAI;IACb;EACF;EAEAG,eAAeA,CAGbC,MAAkB,EAAEC,IAAgB,EAAE;IAAA,IAAAC,iBAAA;IACtC,QAAAA,iBAAA,GAAQ,IAAI,CAACZ,OAAO,CAACK,GAAG,CAACK,MAAM,CAAC,qBAAzBE,iBAAA,CACLD,IAAI,CACL;EACH;AACF;AAACE,OAAA,CAAAC,OAAA,GAAApB,UAAA"} |
|||
@ -1,176 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
exports.setInnerComments = setInnerComments; |
|||
var _base = require("./base"); |
|||
function setTrailingComments(node, comments) { |
|||
if (node.trailingComments === undefined) { |
|||
node.trailingComments = comments; |
|||
} else { |
|||
node.trailingComments.unshift(...comments); |
|||
} |
|||
} |
|||
function setLeadingComments(node, comments) { |
|||
if (node.leadingComments === undefined) { |
|||
node.leadingComments = comments; |
|||
} else { |
|||
node.leadingComments.unshift(...comments); |
|||
} |
|||
} |
|||
function setInnerComments(node, comments) { |
|||
if (node.innerComments === undefined) { |
|||
node.innerComments = comments; |
|||
} else { |
|||
node.innerComments.unshift(...comments); |
|||
} |
|||
} |
|||
function adjustInnerComments(node, elements, commentWS) { |
|||
let lastElement = null; |
|||
let i = elements.length; |
|||
while (lastElement === null && i > 0) { |
|||
lastElement = elements[--i]; |
|||
} |
|||
if (lastElement === null || lastElement.start > commentWS.start) { |
|||
setInnerComments(node, commentWS.comments); |
|||
} else { |
|||
setTrailingComments(lastElement, commentWS.comments); |
|||
} |
|||
} |
|||
class CommentsParser extends _base.default { |
|||
addComment(comment) { |
|||
if (this.filename) comment.loc.filename = this.filename; |
|||
this.state.comments.push(comment); |
|||
} |
|||
processComment(node) { |
|||
const { |
|||
commentStack |
|||
} = this.state; |
|||
const commentStackLength = commentStack.length; |
|||
if (commentStackLength === 0) return; |
|||
let i = commentStackLength - 1; |
|||
const lastCommentWS = commentStack[i]; |
|||
if (lastCommentWS.start === node.end) { |
|||
lastCommentWS.leadingNode = node; |
|||
i--; |
|||
} |
|||
const { |
|||
start: nodeStart |
|||
} = node; |
|||
for (; i >= 0; i--) { |
|||
const commentWS = commentStack[i]; |
|||
const commentEnd = commentWS.end; |
|||
if (commentEnd > nodeStart) { |
|||
commentWS.containingNode = node; |
|||
this.finalizeComment(commentWS); |
|||
commentStack.splice(i, 1); |
|||
} else { |
|||
if (commentEnd === nodeStart) { |
|||
commentWS.trailingNode = node; |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
finalizeComment(commentWS) { |
|||
const { |
|||
comments |
|||
} = commentWS; |
|||
if (commentWS.leadingNode !== null || commentWS.trailingNode !== null) { |
|||
if (commentWS.leadingNode !== null) { |
|||
setTrailingComments(commentWS.leadingNode, comments); |
|||
} |
|||
if (commentWS.trailingNode !== null) { |
|||
setLeadingComments(commentWS.trailingNode, comments); |
|||
} |
|||
} else { |
|||
const { |
|||
containingNode: node, |
|||
start: commentStart |
|||
} = commentWS; |
|||
if (this.input.charCodeAt(commentStart - 1) === 44) { |
|||
switch (node.type) { |
|||
case "ObjectExpression": |
|||
case "ObjectPattern": |
|||
case "RecordExpression": |
|||
adjustInnerComments(node, node.properties, commentWS); |
|||
break; |
|||
case "CallExpression": |
|||
case "OptionalCallExpression": |
|||
adjustInnerComments(node, node.arguments, commentWS); |
|||
break; |
|||
case "FunctionDeclaration": |
|||
case "FunctionExpression": |
|||
case "ArrowFunctionExpression": |
|||
case "ObjectMethod": |
|||
case "ClassMethod": |
|||
case "ClassPrivateMethod": |
|||
adjustInnerComments(node, node.params, commentWS); |
|||
break; |
|||
case "ArrayExpression": |
|||
case "ArrayPattern": |
|||
case "TupleExpression": |
|||
adjustInnerComments(node, node.elements, commentWS); |
|||
break; |
|||
case "ExportNamedDeclaration": |
|||
case "ImportDeclaration": |
|||
adjustInnerComments(node, node.specifiers, commentWS); |
|||
break; |
|||
default: |
|||
{ |
|||
setInnerComments(node, comments); |
|||
} |
|||
} |
|||
} else { |
|||
setInnerComments(node, comments); |
|||
} |
|||
} |
|||
} |
|||
finalizeRemainingComments() { |
|||
const { |
|||
commentStack |
|||
} = this.state; |
|||
for (let i = commentStack.length - 1; i >= 0; i--) { |
|||
this.finalizeComment(commentStack[i]); |
|||
} |
|||
this.state.commentStack = []; |
|||
} |
|||
resetPreviousNodeTrailingComments(node) { |
|||
const { |
|||
commentStack |
|||
} = this.state; |
|||
const { |
|||
length |
|||
} = commentStack; |
|||
if (length === 0) return; |
|||
const commentWS = commentStack[length - 1]; |
|||
if (commentWS.leadingNode === node) { |
|||
commentWS.leadingNode = null; |
|||
} |
|||
} |
|||
takeSurroundingComments(node, start, end) { |
|||
const { |
|||
commentStack |
|||
} = this.state; |
|||
const commentStackLength = commentStack.length; |
|||
if (commentStackLength === 0) return; |
|||
let i = commentStackLength - 1; |
|||
for (; i >= 0; i--) { |
|||
const commentWS = commentStack[i]; |
|||
const commentEnd = commentWS.end; |
|||
const commentStart = commentWS.start; |
|||
if (commentStart === end) { |
|||
commentWS.leadingNode = node; |
|||
} else if (commentEnd === start) { |
|||
commentWS.trailingNode = node; |
|||
} else if (commentEnd < start) { |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
exports.default = CommentsParser; |
|||
|
|||
//# sourceMappingURL=comments.js.map
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,43 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _options = require("../options"); |
|||
var _statement = require("./statement"); |
|||
var _scope = require("../util/scope"); |
|||
class Parser extends _statement.default { |
|||
constructor(options, input) { |
|||
options = (0, _options.getOptions)(options); |
|||
super(options, input); |
|||
this.options = options; |
|||
this.initializeScopes(); |
|||
this.plugins = pluginsMap(this.options.plugins); |
|||
this.filename = options.sourceFilename; |
|||
} |
|||
getScopeHandler() { |
|||
return _scope.default; |
|||
} |
|||
parse() { |
|||
this.enterInitialScopes(); |
|||
const file = this.startNode(); |
|||
const program = this.startNode(); |
|||
this.nextToken(); |
|||
file.errors = null; |
|||
this.parseTopLevel(file, program); |
|||
file.errors = this.state.errors; |
|||
return file; |
|||
} |
|||
} |
|||
exports.default = Parser; |
|||
function pluginsMap(plugins) { |
|||
const pluginMap = new Map(); |
|||
for (const plugin of plugins) { |
|||
const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}]; |
|||
if (!pluginMap.has(name)) pluginMap.set(name, options || {}); |
|||
} |
|||
return pluginMap; |
|||
} |
|||
|
|||
//# sourceMappingURL=index.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_options","require","_statement","_scope","Parser","StatementParser","constructor","options","input","getOptions","initializeScopes","plugins","pluginsMap","filename","sourceFilename","getScopeHandler","ScopeHandler","parse","enterInitialScopes","file","startNode","program","nextToken","errors","parseTopLevel","state","exports","default","pluginMap","Map","plugin","name","Array","isArray","has","set"],"sources":["../../src/parser/index.ts"],"sourcesContent":["import type { Options } from \"../options\";\nimport type * as N from \"../types\";\nimport type { PluginList } from \"../plugin-utils\";\nimport { getOptions } from \"../options\";\nimport StatementParser from \"./statement\";\nimport ScopeHandler from \"../util/scope\";\n\nexport type PluginsMap = Map<\n string,\n {\n [x: string]: any;\n }\n>;\n\nexport default class Parser extends StatementParser {\n // Forward-declaration so typescript plugin can override jsx plugin\n // todo(flow->ts) - this probably can be removed\n // abstract jsxParseOpeningElementAfterName(\n // node: N.JSXOpeningElement,\n // ): N.JSXOpeningElement;\n\n constructor(options: Options | undefined | null, input: string) {\n options = getOptions(options);\n super(options, input);\n\n this.options = options;\n this.initializeScopes();\n this.plugins = pluginsMap(this.options.plugins);\n this.filename = options.sourceFilename;\n }\n\n // This can be overwritten, for example, by the TypeScript plugin.\n getScopeHandler(): {\n new (...args: any): ScopeHandler;\n } {\n return ScopeHandler;\n }\n\n parse(): N.File {\n this.enterInitialScopes();\n const file = this.startNode() as N.File;\n const program = this.startNode() as N.Program;\n this.nextToken();\n file.errors = null;\n this.parseTopLevel(file, program);\n file.errors = this.state.errors;\n return file;\n }\n}\n\nfunction pluginsMap(plugins: PluginList): PluginsMap {\n const pluginMap: PluginsMap = new Map();\n for (const plugin of plugins) {\n const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];\n if (!pluginMap.has(name)) pluginMap.set(name, options || {});\n }\n return pluginMap;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AASe,MAAMG,MAAM,SAASC,kBAAe,CAAC;EAOlDC,WAAWA,CAACC,OAAmC,EAAEC,KAAa,EAAE;IAC9DD,OAAO,GAAG,IAAAE,mBAAU,EAACF,OAAO,CAAC;IAC7B,KAAK,CAACA,OAAO,EAAEC,KAAK,CAAC;IAErB,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACG,gBAAgB,EAAE;IACvB,IAAI,CAACC,OAAO,GAAGC,UAAU,CAAC,IAAI,CAACL,OAAO,CAACI,OAAO,CAAC;IAC/C,IAAI,CAACE,QAAQ,GAAGN,OAAO,CAACO,cAAc;EACxC;EAGAC,eAAeA,CAAA,EAEb;IACA,OAAOC,cAAY;EACrB;EAEAC,KAAKA,CAAA,EAAW;IACd,IAAI,CAACC,kBAAkB,EAAE;IACzB,MAAMC,IAAI,GAAG,IAAI,CAACC,SAAS,EAAY;IACvC,MAAMC,OAAO,GAAG,IAAI,CAACD,SAAS,EAAe;IAC7C,IAAI,CAACE,SAAS,EAAE;IAChBH,IAAI,CAACI,MAAM,GAAG,IAAI;IAClB,IAAI,CAACC,aAAa,CAACL,IAAI,EAAEE,OAAO,CAAC;IACjCF,IAAI,CAACI,MAAM,GAAG,IAAI,CAACE,KAAK,CAACF,MAAM;IAC/B,OAAOJ,IAAI;EACb;AACF;AAACO,OAAA,CAAAC,OAAA,GAAAvB,MAAA;AAED,SAASQ,UAAUA,CAACD,OAAmB,EAAc;EACnD,MAAMiB,SAAqB,GAAG,IAAIC,GAAG,EAAE;EACvC,KAAK,MAAMC,MAAM,IAAInB,OAAO,EAAE;IAC5B,MAAM,CAACoB,IAAI,EAAExB,OAAO,CAAC,GAAGyB,KAAK,CAACC,OAAO,CAACH,MAAM,CAAC,GAAGA,MAAM,GAAG,CAACA,MAAM,EAAE,CAAC,CAAC,CAAC;IACrE,IAAI,CAACF,SAAS,CAACM,GAAG,CAACH,IAAI,CAAC,EAAEH,SAAS,CAACO,GAAG,CAACJ,IAAI,EAAExB,OAAO,IAAI,CAAC,CAAC,CAAC;EAC9D;EACA,OAAOqB,SAAS;AAClB"} |
|||
@ -1,421 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.ParseBindingListFlags = void 0; |
|||
var _types = require("../tokenizer/types"); |
|||
var _identifier = require("../util/identifier"); |
|||
var _node = require("./node"); |
|||
var _scopeflags = require("../util/scopeflags"); |
|||
var _parseError = require("../parse-error"); |
|||
const getOwn = (object, key) => Object.hasOwnProperty.call(object, key) && object[key]; |
|||
const unwrapParenthesizedExpression = node => { |
|||
return node.type === "ParenthesizedExpression" ? unwrapParenthesizedExpression(node.expression) : node; |
|||
}; |
|||
var ParseBindingListFlags = { |
|||
ALLOW_EMPTY: 1, |
|||
IS_FUNCTION_PARAMS: 2, |
|||
IS_CONSTRUCTOR_PARAMS: 4 |
|||
}; |
|||
exports.ParseBindingListFlags = ParseBindingListFlags; |
|||
class LValParser extends _node.NodeUtils { |
|||
toAssignable(node, isLHS = false) { |
|||
var _node$extra, _node$extra3; |
|||
let parenthesized = undefined; |
|||
if (node.type === "ParenthesizedExpression" || (_node$extra = node.extra) != null && _node$extra.parenthesized) { |
|||
parenthesized = unwrapParenthesizedExpression(node); |
|||
if (isLHS) { |
|||
if (parenthesized.type === "Identifier") { |
|||
this.expressionScope.recordArrowParameterBindingError(_parseError.Errors.InvalidParenthesizedAssignment, { |
|||
at: node |
|||
}); |
|||
} else if (parenthesized.type !== "MemberExpression") { |
|||
this.raise(_parseError.Errors.InvalidParenthesizedAssignment, { |
|||
at: node |
|||
}); |
|||
} |
|||
} else { |
|||
this.raise(_parseError.Errors.InvalidParenthesizedAssignment, { |
|||
at: node |
|||
}); |
|||
} |
|||
} |
|||
switch (node.type) { |
|||
case "Identifier": |
|||
case "ObjectPattern": |
|||
case "ArrayPattern": |
|||
case "AssignmentPattern": |
|||
case "RestElement": |
|||
break; |
|||
case "ObjectExpression": |
|||
node.type = "ObjectPattern"; |
|||
for (let i = 0, length = node.properties.length, last = length - 1; i < length; i++) { |
|||
var _node$extra2; |
|||
const prop = node.properties[i]; |
|||
const isLast = i === last; |
|||
this.toAssignableObjectExpressionProp(prop, isLast, isLHS); |
|||
if (isLast && prop.type === "RestElement" && (_node$extra2 = node.extra) != null && _node$extra2.trailingCommaLoc) { |
|||
this.raise(_parseError.Errors.RestTrailingComma, { |
|||
at: node.extra.trailingCommaLoc |
|||
}); |
|||
} |
|||
} |
|||
break; |
|||
case "ObjectProperty": |
|||
{ |
|||
const { |
|||
key, |
|||
value |
|||
} = node; |
|||
if (this.isPrivateName(key)) { |
|||
this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start); |
|||
} |
|||
this.toAssignable(value, isLHS); |
|||
break; |
|||
} |
|||
case "SpreadElement": |
|||
{ |
|||
throw new Error("Internal @babel/parser error (this is a bug, please report it)." + " SpreadElement should be converted by .toAssignable's caller."); |
|||
} |
|||
case "ArrayExpression": |
|||
node.type = "ArrayPattern"; |
|||
this.toAssignableList(node.elements, (_node$extra3 = node.extra) == null ? void 0 : _node$extra3.trailingCommaLoc, isLHS); |
|||
break; |
|||
case "AssignmentExpression": |
|||
if (node.operator !== "=") { |
|||
this.raise(_parseError.Errors.MissingEqInAssignment, { |
|||
at: node.left.loc.end |
|||
}); |
|||
} |
|||
node.type = "AssignmentPattern"; |
|||
delete node.operator; |
|||
this.toAssignable(node.left, isLHS); |
|||
break; |
|||
case "ParenthesizedExpression": |
|||
this.toAssignable(parenthesized, isLHS); |
|||
break; |
|||
default: |
|||
} |
|||
} |
|||
toAssignableObjectExpressionProp(prop, isLast, isLHS) { |
|||
if (prop.type === "ObjectMethod") { |
|||
this.raise(prop.kind === "get" || prop.kind === "set" ? _parseError.Errors.PatternHasAccessor : _parseError.Errors.PatternHasMethod, { |
|||
at: prop.key |
|||
}); |
|||
} else if (prop.type === "SpreadElement") { |
|||
prop.type = "RestElement"; |
|||
const arg = prop.argument; |
|||
this.checkToRestConversion(arg, false); |
|||
this.toAssignable(arg, isLHS); |
|||
if (!isLast) { |
|||
this.raise(_parseError.Errors.RestTrailingComma, { |
|||
at: prop |
|||
}); |
|||
} |
|||
} else { |
|||
this.toAssignable(prop, isLHS); |
|||
} |
|||
} |
|||
toAssignableList(exprList, trailingCommaLoc, isLHS) { |
|||
const end = exprList.length - 1; |
|||
for (let i = 0; i <= end; i++) { |
|||
const elt = exprList[i]; |
|||
if (!elt) continue; |
|||
if (elt.type === "SpreadElement") { |
|||
elt.type = "RestElement"; |
|||
const arg = elt.argument; |
|||
this.checkToRestConversion(arg, true); |
|||
this.toAssignable(arg, isLHS); |
|||
} else { |
|||
this.toAssignable(elt, isLHS); |
|||
} |
|||
if (elt.type === "RestElement") { |
|||
if (i < end) { |
|||
this.raise(_parseError.Errors.RestTrailingComma, { |
|||
at: elt |
|||
}); |
|||
} else if (trailingCommaLoc) { |
|||
this.raise(_parseError.Errors.RestTrailingComma, { |
|||
at: trailingCommaLoc |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
isAssignable(node, isBinding) { |
|||
switch (node.type) { |
|||
case "Identifier": |
|||
case "ObjectPattern": |
|||
case "ArrayPattern": |
|||
case "AssignmentPattern": |
|||
case "RestElement": |
|||
return true; |
|||
case "ObjectExpression": |
|||
{ |
|||
const last = node.properties.length - 1; |
|||
return node.properties.every((prop, i) => { |
|||
return prop.type !== "ObjectMethod" && (i === last || prop.type !== "SpreadElement") && this.isAssignable(prop); |
|||
}); |
|||
} |
|||
case "ObjectProperty": |
|||
return this.isAssignable(node.value); |
|||
case "SpreadElement": |
|||
return this.isAssignable(node.argument); |
|||
case "ArrayExpression": |
|||
return node.elements.every(element => element === null || this.isAssignable(element)); |
|||
case "AssignmentExpression": |
|||
return node.operator === "="; |
|||
case "ParenthesizedExpression": |
|||
return this.isAssignable(node.expression); |
|||
case "MemberExpression": |
|||
case "OptionalMemberExpression": |
|||
return !isBinding; |
|||
default: |
|||
return false; |
|||
} |
|||
} |
|||
toReferencedList(exprList, isParenthesizedExpr) { |
|||
return exprList; |
|||
} |
|||
toReferencedListDeep(exprList, isParenthesizedExpr) { |
|||
this.toReferencedList(exprList, isParenthesizedExpr); |
|||
for (const expr of exprList) { |
|||
if ((expr == null ? void 0 : expr.type) === "ArrayExpression") { |
|||
this.toReferencedListDeep(expr.elements); |
|||
} |
|||
} |
|||
} |
|||
parseSpread(refExpressionErrors) { |
|||
const node = this.startNode(); |
|||
this.next(); |
|||
node.argument = this.parseMaybeAssignAllowIn(refExpressionErrors, undefined); |
|||
return this.finishNode(node, "SpreadElement"); |
|||
} |
|||
parseRestBinding() { |
|||
const node = this.startNode(); |
|||
this.next(); |
|||
node.argument = this.parseBindingAtom(); |
|||
return this.finishNode(node, "RestElement"); |
|||
} |
|||
parseBindingAtom() { |
|||
switch (this.state.type) { |
|||
case 0: |
|||
{ |
|||
const node = this.startNode(); |
|||
this.next(); |
|||
node.elements = this.parseBindingList(3, 93, ParseBindingListFlags.ALLOW_EMPTY); |
|||
return this.finishNode(node, "ArrayPattern"); |
|||
} |
|||
case 5: |
|||
return this.parseObjectLike(8, true); |
|||
} |
|||
return this.parseIdentifier(); |
|||
} |
|||
parseBindingList(close, closeCharCode, flags) { |
|||
const allowEmpty = flags & ParseBindingListFlags.ALLOW_EMPTY; |
|||
const elts = []; |
|||
let first = true; |
|||
while (!this.eat(close)) { |
|||
if (first) { |
|||
first = false; |
|||
} else { |
|||
this.expect(12); |
|||
} |
|||
if (allowEmpty && this.match(12)) { |
|||
elts.push(null); |
|||
} else if (this.eat(close)) { |
|||
break; |
|||
} else if (this.match(21)) { |
|||
elts.push(this.parseAssignableListItemTypes(this.parseRestBinding(), flags)); |
|||
if (!this.checkCommaAfterRest(closeCharCode)) { |
|||
this.expect(close); |
|||
break; |
|||
} |
|||
} else { |
|||
const decorators = []; |
|||
if (this.match(26) && this.hasPlugin("decorators")) { |
|||
this.raise(_parseError.Errors.UnsupportedParameterDecorator, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
while (this.match(26)) { |
|||
decorators.push(this.parseDecorator()); |
|||
} |
|||
elts.push(this.parseAssignableListItem(flags, decorators)); |
|||
} |
|||
} |
|||
return elts; |
|||
} |
|||
parseBindingRestProperty(prop) { |
|||
this.next(); |
|||
prop.argument = this.parseIdentifier(); |
|||
this.checkCommaAfterRest(125); |
|||
return this.finishNode(prop, "RestElement"); |
|||
} |
|||
parseBindingProperty() { |
|||
const prop = this.startNode(); |
|||
const { |
|||
type, |
|||
startLoc |
|||
} = this.state; |
|||
if (type === 21) { |
|||
return this.parseBindingRestProperty(prop); |
|||
} else if (type === 136) { |
|||
this.expectPlugin("destructuringPrivate", startLoc); |
|||
this.classScope.usePrivateName(this.state.value, startLoc); |
|||
prop.key = this.parsePrivateName(); |
|||
} else { |
|||
this.parsePropertyName(prop); |
|||
} |
|||
prop.method = false; |
|||
return this.parseObjPropValue(prop, startLoc, false, false, true, false); |
|||
} |
|||
parseAssignableListItem(flags, decorators) { |
|||
const left = this.parseMaybeDefault(); |
|||
this.parseAssignableListItemTypes(left, flags); |
|||
const elt = this.parseMaybeDefault(left.loc.start, left); |
|||
if (decorators.length) { |
|||
left.decorators = decorators; |
|||
} |
|||
return elt; |
|||
} |
|||
parseAssignableListItemTypes(param, flags) { |
|||
return param; |
|||
} |
|||
parseMaybeDefault(startLoc, left) { |
|||
var _startLoc, _left; |
|||
(_startLoc = startLoc) != null ? _startLoc : startLoc = this.state.startLoc; |
|||
left = (_left = left) != null ? _left : this.parseBindingAtom(); |
|||
if (!this.eat(29)) return left; |
|||
const node = this.startNodeAt(startLoc); |
|||
node.left = left; |
|||
node.right = this.parseMaybeAssignAllowIn(); |
|||
return this.finishNode(node, "AssignmentPattern"); |
|||
} |
|||
isValidLVal(type, isUnparenthesizedInAssign, binding) { |
|||
return getOwn({ |
|||
AssignmentPattern: "left", |
|||
RestElement: "argument", |
|||
ObjectProperty: "value", |
|||
ParenthesizedExpression: "expression", |
|||
ArrayPattern: "elements", |
|||
ObjectPattern: "properties" |
|||
}, type); |
|||
} |
|||
checkLVal(expression, { |
|||
in: ancestor, |
|||
binding = _scopeflags.BIND_NONE, |
|||
checkClashes = false, |
|||
strictModeChanged = false, |
|||
hasParenthesizedAncestor = false |
|||
}) { |
|||
var _expression$extra; |
|||
const type = expression.type; |
|||
if (this.isObjectMethod(expression)) return; |
|||
if (type === "MemberExpression") { |
|||
if (binding !== _scopeflags.BIND_NONE) { |
|||
this.raise(_parseError.Errors.InvalidPropertyBindingPattern, { |
|||
at: expression |
|||
}); |
|||
} |
|||
return; |
|||
} |
|||
if (type === "Identifier") { |
|||
this.checkIdentifier(expression, binding, strictModeChanged); |
|||
const { |
|||
name |
|||
} = expression; |
|||
if (checkClashes) { |
|||
if (checkClashes.has(name)) { |
|||
this.raise(_parseError.Errors.ParamDupe, { |
|||
at: expression |
|||
}); |
|||
} else { |
|||
checkClashes.add(name); |
|||
} |
|||
} |
|||
return; |
|||
} |
|||
const validity = this.isValidLVal(type, !(hasParenthesizedAncestor || (_expression$extra = expression.extra) != null && _expression$extra.parenthesized) && ancestor.type === "AssignmentExpression", binding); |
|||
if (validity === true) return; |
|||
if (validity === false) { |
|||
const ParseErrorClass = binding === _scopeflags.BIND_NONE ? _parseError.Errors.InvalidLhs : _parseError.Errors.InvalidLhsBinding; |
|||
this.raise(ParseErrorClass, { |
|||
at: expression, |
|||
ancestor |
|||
}); |
|||
return; |
|||
} |
|||
const [key, isParenthesizedExpression] = Array.isArray(validity) ? validity : [validity, type === "ParenthesizedExpression"]; |
|||
const nextAncestor = type === "ArrayPattern" || type === "ObjectPattern" || type === "ParenthesizedExpression" ? { |
|||
type |
|||
} : ancestor; |
|||
for (const child of [].concat(expression[key])) { |
|||
if (child) { |
|||
this.checkLVal(child, { |
|||
in: nextAncestor, |
|||
binding, |
|||
checkClashes, |
|||
strictModeChanged, |
|||
hasParenthesizedAncestor: isParenthesizedExpression |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
checkIdentifier(at, bindingType, strictModeChanged = false) { |
|||
if (this.state.strict && (strictModeChanged ? (0, _identifier.isStrictBindReservedWord)(at.name, this.inModule) : (0, _identifier.isStrictBindOnlyReservedWord)(at.name))) { |
|||
if (bindingType === _scopeflags.BIND_NONE) { |
|||
this.raise(_parseError.Errors.StrictEvalArguments, { |
|||
at, |
|||
referenceName: at.name |
|||
}); |
|||
} else { |
|||
this.raise(_parseError.Errors.StrictEvalArgumentsBinding, { |
|||
at, |
|||
bindingName: at.name |
|||
}); |
|||
} |
|||
} |
|||
if (bindingType & _scopeflags.BIND_FLAGS_NO_LET_IN_LEXICAL && at.name === "let") { |
|||
this.raise(_parseError.Errors.LetInLexicalBinding, { |
|||
at |
|||
}); |
|||
} |
|||
if (!(bindingType & _scopeflags.BIND_NONE)) { |
|||
this.declareNameFromIdentifier(at, bindingType); |
|||
} |
|||
} |
|||
declareNameFromIdentifier(identifier, binding) { |
|||
this.scope.declareName(identifier.name, binding, identifier.loc.start); |
|||
} |
|||
checkToRestConversion(node, allowPattern) { |
|||
switch (node.type) { |
|||
case "ParenthesizedExpression": |
|||
this.checkToRestConversion(node.expression, allowPattern); |
|||
break; |
|||
case "Identifier": |
|||
case "MemberExpression": |
|||
break; |
|||
case "ArrayExpression": |
|||
case "ObjectExpression": |
|||
if (allowPattern) break; |
|||
default: |
|||
this.raise(_parseError.Errors.InvalidRestAssignmentPattern, { |
|||
at: node |
|||
}); |
|||
} |
|||
} |
|||
checkCommaAfterRest(close) { |
|||
if (!this.match(12)) { |
|||
return false; |
|||
} |
|||
this.raise(this.lookaheadCharCode() === close ? _parseError.Errors.RestTrailingComma : _parseError.Errors.ElementAfterRest, { |
|||
at: this.state.startLoc |
|||
}); |
|||
return true; |
|||
} |
|||
} |
|||
exports.default = LValParser; |
|||
|
|||
//# sourceMappingURL=lval.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,127 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.NodeUtils = void 0; |
|||
exports.cloneIdentifier = cloneIdentifier; |
|||
exports.cloneStringLiteral = cloneStringLiteral; |
|||
var _util = require("./util"); |
|||
var _location = require("../util/location"); |
|||
class Node { |
|||
constructor(parser, pos, loc) { |
|||
this.type = ""; |
|||
this.start = pos; |
|||
this.end = 0; |
|||
this.loc = new _location.SourceLocation(loc); |
|||
if (parser != null && parser.options.ranges) this.range = [pos, 0]; |
|||
if (parser != null && parser.filename) this.loc.filename = parser.filename; |
|||
} |
|||
} |
|||
const NodePrototype = Node.prototype; |
|||
{ |
|||
NodePrototype.__clone = function () { |
|||
const newNode = new Node(undefined, this.start, this.loc.start); |
|||
const keys = Object.keys(this); |
|||
for (let i = 0, length = keys.length; i < length; i++) { |
|||
const key = keys[i]; |
|||
if (key !== "leadingComments" && key !== "trailingComments" && key !== "innerComments") { |
|||
newNode[key] = this[key]; |
|||
} |
|||
} |
|||
return newNode; |
|||
}; |
|||
} |
|||
function clonePlaceholder(node) { |
|||
return cloneIdentifier(node); |
|||
} |
|||
function cloneIdentifier(node) { |
|||
const { |
|||
type, |
|||
start, |
|||
end, |
|||
loc, |
|||
range, |
|||
extra, |
|||
name |
|||
} = node; |
|||
const cloned = Object.create(NodePrototype); |
|||
cloned.type = type; |
|||
cloned.start = start; |
|||
cloned.end = end; |
|||
cloned.loc = loc; |
|||
cloned.range = range; |
|||
cloned.extra = extra; |
|||
cloned.name = name; |
|||
if (type === "Placeholder") { |
|||
cloned.expectedNode = node.expectedNode; |
|||
} |
|||
return cloned; |
|||
} |
|||
function cloneStringLiteral(node) { |
|||
const { |
|||
type, |
|||
start, |
|||
end, |
|||
loc, |
|||
range, |
|||
extra |
|||
} = node; |
|||
if (type === "Placeholder") { |
|||
return clonePlaceholder(node); |
|||
} |
|||
const cloned = Object.create(NodePrototype); |
|||
cloned.type = type; |
|||
cloned.start = start; |
|||
cloned.end = end; |
|||
cloned.loc = loc; |
|||
cloned.range = range; |
|||
if (node.raw !== undefined) { |
|||
cloned.raw = node.raw; |
|||
} else { |
|||
cloned.extra = extra; |
|||
} |
|||
cloned.value = node.value; |
|||
return cloned; |
|||
} |
|||
class NodeUtils extends _util.default { |
|||
startNode() { |
|||
return new Node(this, this.state.start, this.state.startLoc); |
|||
} |
|||
startNodeAt(loc) { |
|||
return new Node(this, loc.index, loc); |
|||
} |
|||
startNodeAtNode(type) { |
|||
return this.startNodeAt(type.loc.start); |
|||
} |
|||
finishNode(node, type) { |
|||
return this.finishNodeAt(node, type, this.state.lastTokEndLoc); |
|||
} |
|||
finishNodeAt(node, type, endLoc) { |
|||
if (process.env.NODE_ENV !== "production" && node.end > 0) { |
|||
throw new Error("Do not call finishNode*() twice on the same node." + " Instead use resetEndLocation() or change type directly."); |
|||
} |
|||
node.type = type; |
|||
node.end = endLoc.index; |
|||
node.loc.end = endLoc; |
|||
if (this.options.ranges) node.range[1] = endLoc.index; |
|||
if (this.options.attachComment) this.processComment(node); |
|||
return node; |
|||
} |
|||
resetStartLocation(node, startLoc) { |
|||
node.start = startLoc.index; |
|||
node.loc.start = startLoc; |
|||
if (this.options.ranges) node.range[0] = startLoc.index; |
|||
} |
|||
resetEndLocation(node, endLoc = this.state.lastTokEndLoc) { |
|||
node.end = endLoc.index; |
|||
node.loc.end = endLoc; |
|||
if (this.options.ranges) node.range[1] = endLoc.index; |
|||
} |
|||
resetStartLocationFromNode(node, locationNode) { |
|||
this.resetStartLocation(node, locationNode.loc.start); |
|||
} |
|||
} |
|||
exports.NodeUtils = NodeUtils; |
|||
|
|||
//# sourceMappingURL=node.js.map
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,238 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.ExpressionErrors = void 0; |
|||
var _types = require("../tokenizer/types"); |
|||
var _tokenizer = require("../tokenizer"); |
|||
var _whitespace = require("../util/whitespace"); |
|||
var _identifier = require("../util/identifier"); |
|||
var _classScope = require("../util/class-scope"); |
|||
var _expressionScope = require("../util/expression-scope"); |
|||
var _scopeflags = require("../util/scopeflags"); |
|||
var _productionParameter = require("../util/production-parameter"); |
|||
var _parseError = require("../parse-error"); |
|||
class UtilParser extends _tokenizer.default { |
|||
addExtra(node, key, value, enumerable = true) { |
|||
if (!node) return; |
|||
const extra = node.extra = node.extra || {}; |
|||
if (enumerable) { |
|||
extra[key] = value; |
|||
} else { |
|||
Object.defineProperty(extra, key, { |
|||
enumerable, |
|||
value |
|||
}); |
|||
} |
|||
} |
|||
isContextual(token) { |
|||
return this.state.type === token && !this.state.containsEsc; |
|||
} |
|||
isUnparsedContextual(nameStart, name) { |
|||
const nameEnd = nameStart + name.length; |
|||
if (this.input.slice(nameStart, nameEnd) === name) { |
|||
const nextCh = this.input.charCodeAt(nameEnd); |
|||
return !((0, _identifier.isIdentifierChar)(nextCh) || (nextCh & 0xfc00) === 0xd800); |
|||
} |
|||
return false; |
|||
} |
|||
isLookaheadContextual(name) { |
|||
const next = this.nextTokenStart(); |
|||
return this.isUnparsedContextual(next, name); |
|||
} |
|||
eatContextual(token) { |
|||
if (this.isContextual(token)) { |
|||
this.next(); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
expectContextual(token, toParseError) { |
|||
if (!this.eatContextual(token)) { |
|||
if (toParseError != null) { |
|||
throw this.raise(toParseError, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
this.unexpected(null, token); |
|||
} |
|||
} |
|||
canInsertSemicolon() { |
|||
return this.match(137) || this.match(8) || this.hasPrecedingLineBreak(); |
|||
} |
|||
hasPrecedingLineBreak() { |
|||
return _whitespace.lineBreak.test(this.input.slice(this.state.lastTokEndLoc.index, this.state.start)); |
|||
} |
|||
hasFollowingLineBreak() { |
|||
_whitespace.skipWhiteSpaceToLineBreak.lastIndex = this.state.end; |
|||
return _whitespace.skipWhiteSpaceToLineBreak.test(this.input); |
|||
} |
|||
isLineTerminator() { |
|||
return this.eat(13) || this.canInsertSemicolon(); |
|||
} |
|||
semicolon(allowAsi = true) { |
|||
if (allowAsi ? this.isLineTerminator() : this.eat(13)) return; |
|||
this.raise(_parseError.Errors.MissingSemicolon, { |
|||
at: this.state.lastTokEndLoc |
|||
}); |
|||
} |
|||
expect(type, loc) { |
|||
this.eat(type) || this.unexpected(loc, type); |
|||
} |
|||
tryParse(fn, oldState = this.state.clone()) { |
|||
const abortSignal = { |
|||
node: null |
|||
}; |
|||
try { |
|||
const node = fn((node = null) => { |
|||
abortSignal.node = node; |
|||
throw abortSignal; |
|||
}); |
|||
if (this.state.errors.length > oldState.errors.length) { |
|||
const failState = this.state; |
|||
this.state = oldState; |
|||
this.state.tokensLength = failState.tokensLength; |
|||
return { |
|||
node, |
|||
error: failState.errors[oldState.errors.length], |
|||
thrown: false, |
|||
aborted: false, |
|||
failState |
|||
}; |
|||
} |
|||
return { |
|||
node, |
|||
error: null, |
|||
thrown: false, |
|||
aborted: false, |
|||
failState: null |
|||
}; |
|||
} catch (error) { |
|||
const failState = this.state; |
|||
this.state = oldState; |
|||
if (error instanceof SyntaxError) { |
|||
return { |
|||
node: null, |
|||
error, |
|||
thrown: true, |
|||
aborted: false, |
|||
failState |
|||
}; |
|||
} |
|||
if (error === abortSignal) { |
|||
return { |
|||
node: abortSignal.node, |
|||
error: null, |
|||
thrown: false, |
|||
aborted: true, |
|||
failState |
|||
}; |
|||
} |
|||
throw error; |
|||
} |
|||
} |
|||
checkExpressionErrors(refExpressionErrors, andThrow) { |
|||
if (!refExpressionErrors) return false; |
|||
const { |
|||
shorthandAssignLoc, |
|||
doubleProtoLoc, |
|||
privateKeyLoc, |
|||
optionalParametersLoc |
|||
} = refExpressionErrors; |
|||
const hasErrors = !!shorthandAssignLoc || !!doubleProtoLoc || !!optionalParametersLoc || !!privateKeyLoc; |
|||
if (!andThrow) { |
|||
return hasErrors; |
|||
} |
|||
if (shorthandAssignLoc != null) { |
|||
this.raise(_parseError.Errors.InvalidCoverInitializedName, { |
|||
at: shorthandAssignLoc |
|||
}); |
|||
} |
|||
if (doubleProtoLoc != null) { |
|||
this.raise(_parseError.Errors.DuplicateProto, { |
|||
at: doubleProtoLoc |
|||
}); |
|||
} |
|||
if (privateKeyLoc != null) { |
|||
this.raise(_parseError.Errors.UnexpectedPrivateField, { |
|||
at: privateKeyLoc |
|||
}); |
|||
} |
|||
if (optionalParametersLoc != null) { |
|||
this.unexpected(optionalParametersLoc); |
|||
} |
|||
} |
|||
isLiteralPropertyName() { |
|||
return (0, _types.tokenIsLiteralPropertyName)(this.state.type); |
|||
} |
|||
isPrivateName(node) { |
|||
return node.type === "PrivateName"; |
|||
} |
|||
getPrivateNameSV(node) { |
|||
return node.id.name; |
|||
} |
|||
hasPropertyAsPrivateName(node) { |
|||
return (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && this.isPrivateName(node.property); |
|||
} |
|||
isObjectProperty(node) { |
|||
return node.type === "ObjectProperty"; |
|||
} |
|||
isObjectMethod(node) { |
|||
return node.type === "ObjectMethod"; |
|||
} |
|||
initializeScopes(inModule = this.options.sourceType === "module") { |
|||
const oldLabels = this.state.labels; |
|||
this.state.labels = []; |
|||
const oldExportedIdentifiers = this.exportedIdentifiers; |
|||
this.exportedIdentifiers = new Set(); |
|||
const oldInModule = this.inModule; |
|||
this.inModule = inModule; |
|||
const oldScope = this.scope; |
|||
const ScopeHandler = this.getScopeHandler(); |
|||
this.scope = new ScopeHandler(this, inModule); |
|||
const oldProdParam = this.prodParam; |
|||
this.prodParam = new _productionParameter.default(); |
|||
const oldClassScope = this.classScope; |
|||
this.classScope = new _classScope.default(this); |
|||
const oldExpressionScope = this.expressionScope; |
|||
this.expressionScope = new _expressionScope.default(this); |
|||
return () => { |
|||
this.state.labels = oldLabels; |
|||
this.exportedIdentifiers = oldExportedIdentifiers; |
|||
this.inModule = oldInModule; |
|||
this.scope = oldScope; |
|||
this.prodParam = oldProdParam; |
|||
this.classScope = oldClassScope; |
|||
this.expressionScope = oldExpressionScope; |
|||
}; |
|||
} |
|||
enterInitialScopes() { |
|||
let paramFlags = _productionParameter.PARAM; |
|||
if (this.inModule) { |
|||
paramFlags |= _productionParameter.PARAM_AWAIT; |
|||
} |
|||
this.scope.enter(_scopeflags.SCOPE_PROGRAM); |
|||
this.prodParam.enter(paramFlags); |
|||
} |
|||
checkDestructuringPrivate(refExpressionErrors) { |
|||
const { |
|||
privateKeyLoc |
|||
} = refExpressionErrors; |
|||
if (privateKeyLoc !== null) { |
|||
this.expectPlugin("destructuringPrivate", privateKeyLoc); |
|||
} |
|||
} |
|||
} |
|||
exports.default = UtilParser; |
|||
class ExpressionErrors { |
|||
constructor() { |
|||
this.shorthandAssignLoc = null; |
|||
this.doubleProtoLoc = null; |
|||
this.privateKeyLoc = null; |
|||
this.optionalParametersLoc = null; |
|||
} |
|||
} |
|||
exports.ExpressionErrors = ExpressionErrors; |
|||
|
|||
//# sourceMappingURL=util.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,133 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.getPluginOption = getPluginOption; |
|||
exports.hasPlugin = hasPlugin; |
|||
exports.mixinPlugins = exports.mixinPluginNames = void 0; |
|||
exports.validatePlugins = validatePlugins; |
|||
var _estree = require("./plugins/estree"); |
|||
var _flow = require("./plugins/flow"); |
|||
var _jsx = require("./plugins/jsx"); |
|||
var _typescript = require("./plugins/typescript"); |
|||
var _placeholders = require("./plugins/placeholders"); |
|||
var _v8intrinsic = require("./plugins/v8intrinsic"); |
|||
function hasPlugin(plugins, expectedConfig) { |
|||
const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig; |
|||
const expectedKeys = Object.keys(expectedOptions); |
|||
const expectedOptionsIsEmpty = expectedKeys.length === 0; |
|||
return plugins.some(p => { |
|||
if (typeof p === "string") { |
|||
return expectedOptionsIsEmpty && p === expectedName; |
|||
} else { |
|||
const [pluginName, pluginOptions] = p; |
|||
if (pluginName !== expectedName) { |
|||
return false; |
|||
} |
|||
for (const key of expectedKeys) { |
|||
if (pluginOptions[key] !== expectedOptions[key]) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
}); |
|||
} |
|||
function getPluginOption(plugins, name, option) { |
|||
const plugin = plugins.find(plugin => { |
|||
if (Array.isArray(plugin)) { |
|||
return plugin[0] === name; |
|||
} else { |
|||
return plugin === name; |
|||
} |
|||
}); |
|||
if (plugin && Array.isArray(plugin) && plugin.length > 1) { |
|||
return plugin[1][option]; |
|||
} |
|||
return null; |
|||
} |
|||
const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"]; |
|||
const TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"]; |
|||
const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"]; |
|||
function validatePlugins(plugins) { |
|||
if (hasPlugin(plugins, "decorators")) { |
|||
if (hasPlugin(plugins, "decorators-legacy")) { |
|||
throw new Error("Cannot use the decorators and decorators-legacy plugin together"); |
|||
} |
|||
const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport"); |
|||
if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") { |
|||
throw new Error("'decoratorsBeforeExport' must be a boolean, if specified."); |
|||
} |
|||
const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized"); |
|||
if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") { |
|||
throw new Error("'allowCallParenthesized' must be a boolean."); |
|||
} |
|||
} |
|||
if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) { |
|||
throw new Error("Cannot combine flow and typescript plugins."); |
|||
} |
|||
if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) { |
|||
throw new Error("Cannot combine placeholders and v8intrinsic plugins."); |
|||
} |
|||
if (hasPlugin(plugins, "pipelineOperator")) { |
|||
const proposal = getPluginOption(plugins, "pipelineOperator", "proposal"); |
|||
if (!PIPELINE_PROPOSALS.includes(proposal)) { |
|||
const proposalList = PIPELINE_PROPOSALS.map(p => `"${p}"`).join(", "); |
|||
throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`); |
|||
} |
|||
const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", { |
|||
syntaxType: "hash" |
|||
}]); |
|||
if (proposal === "hack") { |
|||
if (hasPlugin(plugins, "placeholders")) { |
|||
throw new Error("Cannot combine placeholders plugin and Hack-style pipes."); |
|||
} |
|||
if (hasPlugin(plugins, "v8intrinsic")) { |
|||
throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes."); |
|||
} |
|||
const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken"); |
|||
if (!TOPIC_TOKENS.includes(topicToken)) { |
|||
const tokenList = TOPIC_TOKENS.map(t => `"${t}"`).join(", "); |
|||
throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`); |
|||
} |
|||
if (topicToken === "#" && tupleSyntaxIsHash) { |
|||
throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "hack", topicToken: "#" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.'); |
|||
} |
|||
} else if (proposal === "smart" && tupleSyntaxIsHash) { |
|||
throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.'); |
|||
} |
|||
} |
|||
if (hasPlugin(plugins, "moduleAttributes")) { |
|||
{ |
|||
if (hasPlugin(plugins, "importAssertions")) { |
|||
throw new Error("Cannot combine importAssertions and moduleAttributes plugins."); |
|||
} |
|||
const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version"); |
|||
if (moduleAttributesVersionPluginOption !== "may-2020") { |
|||
throw new Error("The 'moduleAttributes' plugin requires a 'version' option," + " representing the last proposal update. Currently, the" + " only supported value is 'may-2020'."); |
|||
} |
|||
} |
|||
} |
|||
if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) { |
|||
throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map(p => `'${p}'`).join(", ")); |
|||
} |
|||
if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) { |
|||
const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins."); |
|||
error.missingPlugins = "doExpressions"; |
|||
throw error; |
|||
} |
|||
} |
|||
const mixinPlugins = { |
|||
estree: _estree.default, |
|||
jsx: _jsx.default, |
|||
flow: _flow.default, |
|||
typescript: _typescript.default, |
|||
v8intrinsic: _v8intrinsic.default, |
|||
placeholders: _placeholders.default |
|||
}; |
|||
exports.mixinPlugins = mixinPlugins; |
|||
const mixinPluginNames = Object.keys(mixinPlugins); |
|||
exports.mixinPluginNames = mixinPluginNames; |
|||
|
|||
//# sourceMappingURL=plugin-utils.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,340 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _parseError = require("../parse-error"); |
|||
const { |
|||
defineProperty |
|||
} = Object; |
|||
const toUnenumerable = (object, key) => defineProperty(object, key, { |
|||
enumerable: false, |
|||
value: object[key] |
|||
}); |
|||
function toESTreeLocation(node) { |
|||
node.loc.start && toUnenumerable(node.loc.start, "index"); |
|||
node.loc.end && toUnenumerable(node.loc.end, "index"); |
|||
return node; |
|||
} |
|||
var _default = superClass => class ESTreeParserMixin extends superClass { |
|||
parse() { |
|||
const file = toESTreeLocation(super.parse()); |
|||
if (this.options.tokens) { |
|||
file.tokens = file.tokens.map(toESTreeLocation); |
|||
} |
|||
return file; |
|||
} |
|||
parseRegExpLiteral({ |
|||
pattern, |
|||
flags |
|||
}) { |
|||
let regex = null; |
|||
try { |
|||
regex = new RegExp(pattern, flags); |
|||
} catch (e) {} |
|||
const node = this.estreeParseLiteral(regex); |
|||
node.regex = { |
|||
pattern, |
|||
flags |
|||
}; |
|||
return node; |
|||
} |
|||
parseBigIntLiteral(value) { |
|||
let bigInt; |
|||
try { |
|||
bigInt = BigInt(value); |
|||
} catch (_unused) { |
|||
bigInt = null; |
|||
} |
|||
const node = this.estreeParseLiteral(bigInt); |
|||
node.bigint = String(node.value || value); |
|||
return node; |
|||
} |
|||
parseDecimalLiteral(value) { |
|||
const decimal = null; |
|||
const node = this.estreeParseLiteral(decimal); |
|||
node.decimal = String(node.value || value); |
|||
return node; |
|||
} |
|||
estreeParseLiteral(value) { |
|||
return this.parseLiteral(value, "Literal"); |
|||
} |
|||
parseStringLiteral(value) { |
|||
return this.estreeParseLiteral(value); |
|||
} |
|||
parseNumericLiteral(value) { |
|||
return this.estreeParseLiteral(value); |
|||
} |
|||
parseNullLiteral() { |
|||
return this.estreeParseLiteral(null); |
|||
} |
|||
parseBooleanLiteral(value) { |
|||
return this.estreeParseLiteral(value); |
|||
} |
|||
directiveToStmt(directive) { |
|||
const expression = directive.value; |
|||
delete directive.value; |
|||
expression.type = "Literal"; |
|||
expression.raw = expression.extra.raw; |
|||
expression.value = expression.extra.expressionValue; |
|||
const stmt = directive; |
|||
stmt.type = "ExpressionStatement"; |
|||
stmt.expression = expression; |
|||
stmt.directive = expression.extra.rawValue; |
|||
delete expression.extra; |
|||
return stmt; |
|||
} |
|||
initFunction(node, isAsync) { |
|||
super.initFunction(node, isAsync); |
|||
node.expression = false; |
|||
} |
|||
checkDeclaration(node) { |
|||
if (node != null && this.isObjectProperty(node)) { |
|||
this.checkDeclaration(node.value); |
|||
} else { |
|||
super.checkDeclaration(node); |
|||
} |
|||
} |
|||
getObjectOrClassMethodParams(method) { |
|||
return method.value.params; |
|||
} |
|||
isValidDirective(stmt) { |
|||
var _stmt$expression$extr; |
|||
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && !((_stmt$expression$extr = stmt.expression.extra) != null && _stmt$expression$extr.parenthesized); |
|||
} |
|||
parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) { |
|||
super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse); |
|||
const directiveStatements = node.directives.map(d => this.directiveToStmt(d)); |
|||
node.body = directiveStatements.concat(node.body); |
|||
delete node.directives; |
|||
} |
|||
pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) { |
|||
this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true); |
|||
if (method.typeParameters) { |
|||
method.value.typeParameters = method.typeParameters; |
|||
delete method.typeParameters; |
|||
} |
|||
classBody.body.push(method); |
|||
} |
|||
parsePrivateName() { |
|||
const node = super.parsePrivateName(); |
|||
{ |
|||
if (!this.getPluginOption("estree", "classFeatures")) { |
|||
return node; |
|||
} |
|||
} |
|||
return this.convertPrivateNameToPrivateIdentifier(node); |
|||
} |
|||
convertPrivateNameToPrivateIdentifier(node) { |
|||
const name = super.getPrivateNameSV(node); |
|||
node = node; |
|||
delete node.id; |
|||
node.name = name; |
|||
node.type = "PrivateIdentifier"; |
|||
return node; |
|||
} |
|||
isPrivateName(node) { |
|||
{ |
|||
if (!this.getPluginOption("estree", "classFeatures")) { |
|||
return super.isPrivateName(node); |
|||
} |
|||
} |
|||
return node.type === "PrivateIdentifier"; |
|||
} |
|||
getPrivateNameSV(node) { |
|||
{ |
|||
if (!this.getPluginOption("estree", "classFeatures")) { |
|||
return super.getPrivateNameSV(node); |
|||
} |
|||
} |
|||
return node.name; |
|||
} |
|||
parseLiteral(value, type) { |
|||
const node = super.parseLiteral(value, type); |
|||
node.raw = node.extra.raw; |
|||
delete node.extra; |
|||
return node; |
|||
} |
|||
parseFunctionBody(node, allowExpression, isMethod = false) { |
|||
super.parseFunctionBody(node, allowExpression, isMethod); |
|||
node.expression = node.body.type !== "BlockStatement"; |
|||
} |
|||
parseMethod(node, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope = false) { |
|||
let funcNode = this.startNode(); |
|||
funcNode.kind = node.kind; |
|||
funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, allowDirectSuper, type, inClassScope); |
|||
funcNode.type = "FunctionExpression"; |
|||
delete funcNode.kind; |
|||
node.value = funcNode; |
|||
if (type === "ClassPrivateMethod") { |
|||
node.computed = false; |
|||
} |
|||
return this.finishNode(node, "MethodDefinition"); |
|||
} |
|||
parseClassProperty(...args) { |
|||
const propertyNode = super.parseClassProperty(...args); |
|||
{ |
|||
if (!this.getPluginOption("estree", "classFeatures")) { |
|||
return propertyNode; |
|||
} |
|||
} |
|||
propertyNode.type = "PropertyDefinition"; |
|||
return propertyNode; |
|||
} |
|||
parseClassPrivateProperty(...args) { |
|||
const propertyNode = super.parseClassPrivateProperty(...args); |
|||
{ |
|||
if (!this.getPluginOption("estree", "classFeatures")) { |
|||
return propertyNode; |
|||
} |
|||
} |
|||
propertyNode.type = "PropertyDefinition"; |
|||
propertyNode.computed = false; |
|||
return propertyNode; |
|||
} |
|||
parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor) { |
|||
const node = super.parseObjectMethod(prop, isGenerator, isAsync, isPattern, isAccessor); |
|||
if (node) { |
|||
node.type = "Property"; |
|||
if (node.kind === "method") { |
|||
node.kind = "init"; |
|||
} |
|||
node.shorthand = false; |
|||
} |
|||
return node; |
|||
} |
|||
parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors) { |
|||
const node = super.parseObjectProperty(prop, startLoc, isPattern, refExpressionErrors); |
|||
if (node) { |
|||
node.kind = "init"; |
|||
node.type = "Property"; |
|||
} |
|||
return node; |
|||
} |
|||
isValidLVal(type, isUnparenthesizedInAssign, binding) { |
|||
return type === "Property" ? "value" : super.isValidLVal(type, isUnparenthesizedInAssign, binding); |
|||
} |
|||
isAssignable(node, isBinding) { |
|||
if (node != null && this.isObjectProperty(node)) { |
|||
return this.isAssignable(node.value, isBinding); |
|||
} |
|||
return super.isAssignable(node, isBinding); |
|||
} |
|||
toAssignable(node, isLHS = false) { |
|||
if (node != null && this.isObjectProperty(node)) { |
|||
const { |
|||
key, |
|||
value |
|||
} = node; |
|||
if (this.isPrivateName(key)) { |
|||
this.classScope.usePrivateName(this.getPrivateNameSV(key), key.loc.start); |
|||
} |
|||
this.toAssignable(value, isLHS); |
|||
} else { |
|||
super.toAssignable(node, isLHS); |
|||
} |
|||
} |
|||
toAssignableObjectExpressionProp(prop, isLast, isLHS) { |
|||
if (prop.kind === "get" || prop.kind === "set") { |
|||
this.raise(_parseError.Errors.PatternHasAccessor, { |
|||
at: prop.key |
|||
}); |
|||
} else if (prop.method) { |
|||
this.raise(_parseError.Errors.PatternHasMethod, { |
|||
at: prop.key |
|||
}); |
|||
} else { |
|||
super.toAssignableObjectExpressionProp(prop, isLast, isLHS); |
|||
} |
|||
} |
|||
finishCallExpression(unfinished, optional) { |
|||
const node = super.finishCallExpression(unfinished, optional); |
|||
if (node.callee.type === "Import") { |
|||
node.type = "ImportExpression"; |
|||
node.source = node.arguments[0]; |
|||
if (this.hasPlugin("importAssertions")) { |
|||
var _node$arguments$; |
|||
node.attributes = (_node$arguments$ = node.arguments[1]) != null ? _node$arguments$ : null; |
|||
} |
|||
delete node.arguments; |
|||
delete node.callee; |
|||
} |
|||
return node; |
|||
} |
|||
toReferencedArguments(node) { |
|||
if (node.type === "ImportExpression") { |
|||
return; |
|||
} |
|||
super.toReferencedArguments(node); |
|||
} |
|||
parseExport(unfinished, decorators) { |
|||
const exportStartLoc = this.state.lastTokStartLoc; |
|||
const node = super.parseExport(unfinished, decorators); |
|||
switch (node.type) { |
|||
case "ExportAllDeclaration": |
|||
node.exported = null; |
|||
break; |
|||
case "ExportNamedDeclaration": |
|||
if (node.specifiers.length === 1 && node.specifiers[0].type === "ExportNamespaceSpecifier") { |
|||
node.type = "ExportAllDeclaration"; |
|||
node.exported = node.specifiers[0].exported; |
|||
delete node.specifiers; |
|||
} |
|||
case "ExportDefaultDeclaration": |
|||
{ |
|||
var _declaration$decorato; |
|||
const { |
|||
declaration |
|||
} = node; |
|||
if ((declaration == null ? void 0 : declaration.type) === "ClassDeclaration" && ((_declaration$decorato = declaration.decorators) == null ? void 0 : _declaration$decorato.length) > 0 && declaration.start === node.start) { |
|||
this.resetStartLocation(node, exportStartLoc); |
|||
} |
|||
} |
|||
break; |
|||
} |
|||
return node; |
|||
} |
|||
parseSubscript(base, startLoc, noCalls, state) { |
|||
const node = super.parseSubscript(base, startLoc, noCalls, state); |
|||
if (state.optionalChainMember) { |
|||
if (node.type === "OptionalMemberExpression" || node.type === "OptionalCallExpression") { |
|||
node.type = node.type.substring(8); |
|||
} |
|||
if (state.stop) { |
|||
const chain = this.startNodeAtNode(node); |
|||
chain.expression = node; |
|||
return this.finishNode(chain, "ChainExpression"); |
|||
} |
|||
} else if (node.type === "MemberExpression" || node.type === "CallExpression") { |
|||
node.optional = false; |
|||
} |
|||
return node; |
|||
} |
|||
hasPropertyAsPrivateName(node) { |
|||
if (node.type === "ChainExpression") { |
|||
node = node.expression; |
|||
} |
|||
return super.hasPropertyAsPrivateName(node); |
|||
} |
|||
isObjectProperty(node) { |
|||
return node.type === "Property" && node.kind === "init" && !node.method; |
|||
} |
|||
isObjectMethod(node) { |
|||
return node.method || node.kind === "get" || node.kind === "set"; |
|||
} |
|||
finishNodeAt(node, type, endLoc) { |
|||
return toESTreeLocation(super.finishNodeAt(node, type, endLoc)); |
|||
} |
|||
resetStartLocation(node, startLoc) { |
|||
super.resetStartLocation(node, startLoc); |
|||
toESTreeLocation(node); |
|||
} |
|||
resetEndLocation(node, endLoc = this.state.lastTokEndLoc) { |
|||
super.resetEndLocation(node, endLoc); |
|||
toESTreeLocation(node); |
|||
} |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=estree.js.map
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,44 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _scope = require("../../util/scope"); |
|||
var _scopeflags = require("../../util/scopeflags"); |
|||
class FlowScope extends _scope.Scope { |
|||
constructor(...args) { |
|||
super(...args); |
|||
this.declareFunctions = new Set(); |
|||
} |
|||
} |
|||
class FlowScopeHandler extends _scope.default { |
|||
createScope(flags) { |
|||
return new FlowScope(flags); |
|||
} |
|||
declareName(name, bindingType, loc) { |
|||
const scope = this.currentScope(); |
|||
if (bindingType & _scopeflags.BIND_FLAGS_FLOW_DECLARE_FN) { |
|||
this.checkRedeclarationInScope(scope, name, bindingType, loc); |
|||
this.maybeExportDefined(scope, name); |
|||
scope.declareFunctions.add(name); |
|||
return; |
|||
} |
|||
super.declareName(name, bindingType, loc); |
|||
} |
|||
isRedeclaredInScope(scope, name, bindingType) { |
|||
if (super.isRedeclaredInScope(scope, name, bindingType)) return true; |
|||
if (bindingType & _scopeflags.BIND_FLAGS_FLOW_DECLARE_FN) { |
|||
return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name)); |
|||
} |
|||
return false; |
|||
} |
|||
checkLocalExport(id) { |
|||
if (!this.scopeStack[0].declareFunctions.has(id.name)) { |
|||
super.checkLocalExport(id); |
|||
} |
|||
} |
|||
} |
|||
exports.default = FlowScopeHandler; |
|||
|
|||
//# sourceMappingURL=scope.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_scope","require","_scopeflags","FlowScope","Scope","constructor","args","declareFunctions","Set","FlowScopeHandler","ScopeHandler","createScope","flags","declareName","name","bindingType","loc","scope","currentScope","BIND_FLAGS_FLOW_DECLARE_FN","checkRedeclarationInScope","maybeExportDefined","add","isRedeclaredInScope","has","lexical","functions","checkLocalExport","id","scopeStack","exports","default"],"sources":["../../../src/plugins/flow/scope.ts"],"sourcesContent":["import type { Position } from \"../../util/location\";\nimport ScopeHandler, { Scope } from \"../../util/scope\";\nimport {\n BIND_FLAGS_FLOW_DECLARE_FN,\n type ScopeFlags,\n type BindingTypes,\n} from \"../../util/scopeflags\";\nimport type * as N from \"../../types\";\n\n// Reference implementation: https://github.com/facebook/flow/blob/23aeb2a2ef6eb4241ce178fde5d8f17c5f747fb5/src/typing/env.ml#L536-L584\nclass FlowScope extends Scope {\n // declare function foo(): type;\n declareFunctions: Set<string> = new Set();\n}\n\nexport default class FlowScopeHandler extends ScopeHandler<FlowScope> {\n createScope(flags: ScopeFlags): FlowScope {\n return new FlowScope(flags);\n }\n\n declareName(name: string, bindingType: BindingTypes, loc: Position) {\n const scope = this.currentScope();\n if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {\n this.checkRedeclarationInScope(scope, name, bindingType, loc);\n this.maybeExportDefined(scope, name);\n scope.declareFunctions.add(name);\n return;\n }\n\n super.declareName(name, bindingType, loc);\n }\n\n isRedeclaredInScope(\n scope: FlowScope,\n name: string,\n bindingType: BindingTypes,\n ): boolean {\n if (super.isRedeclaredInScope(scope, name, bindingType)) return true;\n\n if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {\n return (\n !scope.declareFunctions.has(name) &&\n (scope.lexical.has(name) || scope.functions.has(name))\n );\n }\n\n return false;\n }\n\n checkLocalExport(id: N.Identifier) {\n if (!this.scopeStack[0].declareFunctions.has(id.name)) {\n super.checkLocalExport(id);\n }\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAQA,MAAME,SAAS,SAASC,YAAK,CAAC;EAAAC,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAA,KAE5BC,gBAAgB,GAAgB,IAAIC,GAAG,EAAE;EAAA;AAC3C;AAEe,MAAMC,gBAAgB,SAASC,cAAY,CAAY;EACpEC,WAAWA,CAACC,KAAiB,EAAa;IACxC,OAAO,IAAIT,SAAS,CAACS,KAAK,CAAC;EAC7B;EAEAC,WAAWA,CAACC,IAAY,EAAEC,WAAyB,EAAEC,GAAa,EAAE;IAClE,MAAMC,KAAK,GAAG,IAAI,CAACC,YAAY,EAAE;IACjC,IAAIH,WAAW,GAAGI,sCAA0B,EAAE;MAC5C,IAAI,CAACC,yBAAyB,CAACH,KAAK,EAAEH,IAAI,EAAEC,WAAW,EAAEC,GAAG,CAAC;MAC7D,IAAI,CAACK,kBAAkB,CAACJ,KAAK,EAAEH,IAAI,CAAC;MACpCG,KAAK,CAACV,gBAAgB,CAACe,GAAG,CAACR,IAAI,CAAC;MAChC;IACF;IAEA,KAAK,CAACD,WAAW,CAACC,IAAI,EAAEC,WAAW,EAAEC,GAAG,CAAC;EAC3C;EAEAO,mBAAmBA,CACjBN,KAAgB,EAChBH,IAAY,EACZC,WAAyB,EAChB;IACT,IAAI,KAAK,CAACQ,mBAAmB,CAACN,KAAK,EAAEH,IAAI,EAAEC,WAAW,CAAC,EAAE,OAAO,IAAI;IAEpE,IAAIA,WAAW,GAAGI,sCAA0B,EAAE;MAC5C,OACE,CAACF,KAAK,CAACV,gBAAgB,CAACiB,GAAG,CAACV,IAAI,CAAC,KAChCG,KAAK,CAACQ,OAAO,CAACD,GAAG,CAACV,IAAI,CAAC,IAAIG,KAAK,CAACS,SAAS,CAACF,GAAG,CAACV,IAAI,CAAC,CAAC;IAE1D;IAEA,OAAO,KAAK;EACd;EAEAa,gBAAgBA,CAACC,EAAgB,EAAE;IACjC,IAAI,CAAC,IAAI,CAACC,UAAU,CAAC,CAAC,CAAC,CAACtB,gBAAgB,CAACiB,GAAG,CAACI,EAAE,CAACd,IAAI,CAAC,EAAE;MACrD,KAAK,CAACa,gBAAgB,CAACC,EAAE,CAAC;IAC5B;EACF;AACF;AAACE,OAAA,CAAAC,OAAA,GAAAtB,gBAAA"} |
|||
@ -1,444 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _xhtml = require("./xhtml"); |
|||
var _types = require("../../tokenizer/types"); |
|||
var _context = require("../../tokenizer/context"); |
|||
var _identifier = require("../../util/identifier"); |
|||
var _whitespace = require("../../util/whitespace"); |
|||
var _parseError = require("../../parse-error"); |
|||
const JsxErrors = (0, _parseError.ParseErrorEnum)`jsx`({ |
|||
AttributeIsEmpty: "JSX attributes must only be assigned a non-empty expression.", |
|||
MissingClosingTagElement: ({ |
|||
openingTagName |
|||
}) => `Expected corresponding JSX closing tag for <${openingTagName}>.`, |
|||
MissingClosingTagFragment: "Expected corresponding JSX closing tag for <>.", |
|||
UnexpectedSequenceExpression: "Sequence expressions cannot be directly nested inside JSX. Did you mean to wrap it in parentheses (...)?", |
|||
UnexpectedToken: ({ |
|||
unexpected, |
|||
HTMLEntity |
|||
}) => `Unexpected token \`${unexpected}\`. Did you mean \`${HTMLEntity}\` or \`{'${unexpected}'}\`?`, |
|||
UnsupportedJsxValue: "JSX value should be either an expression or a quoted JSX text.", |
|||
UnterminatedJsxContent: "Unterminated JSX contents.", |
|||
UnwrappedAdjacentJSXElements: "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?" |
|||
}); |
|||
function isFragment(object) { |
|||
return object ? object.type === "JSXOpeningFragment" || object.type === "JSXClosingFragment" : false; |
|||
} |
|||
function getQualifiedJSXName(object) { |
|||
if (object.type === "JSXIdentifier") { |
|||
return object.name; |
|||
} |
|||
if (object.type === "JSXNamespacedName") { |
|||
return object.namespace.name + ":" + object.name.name; |
|||
} |
|||
if (object.type === "JSXMemberExpression") { |
|||
return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property); |
|||
} |
|||
throw new Error("Node had unexpected type: " + object.type); |
|||
} |
|||
var _default = superClass => class JSXParserMixin extends superClass { |
|||
jsxReadToken() { |
|||
let out = ""; |
|||
let chunkStart = this.state.pos; |
|||
for (;;) { |
|||
if (this.state.pos >= this.length) { |
|||
throw this.raise(JsxErrors.UnterminatedJsxContent, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
const ch = this.input.charCodeAt(this.state.pos); |
|||
switch (ch) { |
|||
case 60: |
|||
case 123: |
|||
if (this.state.pos === this.state.start) { |
|||
if (ch === 60 && this.state.canStartJSXElement) { |
|||
++this.state.pos; |
|||
this.finishToken(140); |
|||
} else { |
|||
super.getTokenFromCode(ch); |
|||
} |
|||
return; |
|||
} |
|||
out += this.input.slice(chunkStart, this.state.pos); |
|||
this.finishToken(139, out); |
|||
return; |
|||
case 38: |
|||
out += this.input.slice(chunkStart, this.state.pos); |
|||
out += this.jsxReadEntity(); |
|||
chunkStart = this.state.pos; |
|||
break; |
|||
case 62: |
|||
case 125: |
|||
; |
|||
default: |
|||
if ((0, _whitespace.isNewLine)(ch)) { |
|||
out += this.input.slice(chunkStart, this.state.pos); |
|||
out += this.jsxReadNewLine(true); |
|||
chunkStart = this.state.pos; |
|||
} else { |
|||
++this.state.pos; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
jsxReadNewLine(normalizeCRLF) { |
|||
const ch = this.input.charCodeAt(this.state.pos); |
|||
let out; |
|||
++this.state.pos; |
|||
if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) { |
|||
++this.state.pos; |
|||
out = normalizeCRLF ? "\n" : "\r\n"; |
|||
} else { |
|||
out = String.fromCharCode(ch); |
|||
} |
|||
++this.state.curLine; |
|||
this.state.lineStart = this.state.pos; |
|||
return out; |
|||
} |
|||
jsxReadString(quote) { |
|||
let out = ""; |
|||
let chunkStart = ++this.state.pos; |
|||
for (;;) { |
|||
if (this.state.pos >= this.length) { |
|||
throw this.raise(_parseError.Errors.UnterminatedString, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
const ch = this.input.charCodeAt(this.state.pos); |
|||
if (ch === quote) break; |
|||
if (ch === 38) { |
|||
out += this.input.slice(chunkStart, this.state.pos); |
|||
out += this.jsxReadEntity(); |
|||
chunkStart = this.state.pos; |
|||
} else if ((0, _whitespace.isNewLine)(ch)) { |
|||
out += this.input.slice(chunkStart, this.state.pos); |
|||
out += this.jsxReadNewLine(false); |
|||
chunkStart = this.state.pos; |
|||
} else { |
|||
++this.state.pos; |
|||
} |
|||
} |
|||
out += this.input.slice(chunkStart, this.state.pos++); |
|||
this.finishToken(131, out); |
|||
} |
|||
jsxReadEntity() { |
|||
const startPos = ++this.state.pos; |
|||
if (this.codePointAtPos(this.state.pos) === 35) { |
|||
++this.state.pos; |
|||
let radix = 10; |
|||
if (this.codePointAtPos(this.state.pos) === 120) { |
|||
radix = 16; |
|||
++this.state.pos; |
|||
} |
|||
const codePoint = this.readInt(radix, undefined, false, "bail"); |
|||
if (codePoint !== null && this.codePointAtPos(this.state.pos) === 59) { |
|||
++this.state.pos; |
|||
return String.fromCodePoint(codePoint); |
|||
} |
|||
} else { |
|||
let count = 0; |
|||
let semi = false; |
|||
while (count++ < 10 && this.state.pos < this.length && !(semi = this.codePointAtPos(this.state.pos) == 59)) { |
|||
++this.state.pos; |
|||
} |
|||
if (semi) { |
|||
const desc = this.input.slice(startPos, this.state.pos); |
|||
const entity = _xhtml.default[desc]; |
|||
++this.state.pos; |
|||
if (entity) { |
|||
return entity; |
|||
} |
|||
} |
|||
} |
|||
this.state.pos = startPos; |
|||
return "&"; |
|||
} |
|||
jsxReadWord() { |
|||
let ch; |
|||
const start = this.state.pos; |
|||
do { |
|||
ch = this.input.charCodeAt(++this.state.pos); |
|||
} while ((0, _identifier.isIdentifierChar)(ch) || ch === 45); |
|||
this.finishToken(138, this.input.slice(start, this.state.pos)); |
|||
} |
|||
jsxParseIdentifier() { |
|||
const node = this.startNode(); |
|||
if (this.match(138)) { |
|||
node.name = this.state.value; |
|||
} else if ((0, _types.tokenIsKeyword)(this.state.type)) { |
|||
node.name = (0, _types.tokenLabelName)(this.state.type); |
|||
} else { |
|||
this.unexpected(); |
|||
} |
|||
this.next(); |
|||
return this.finishNode(node, "JSXIdentifier"); |
|||
} |
|||
jsxParseNamespacedName() { |
|||
const startLoc = this.state.startLoc; |
|||
const name = this.jsxParseIdentifier(); |
|||
if (!this.eat(14)) return name; |
|||
const node = this.startNodeAt(startLoc); |
|||
node.namespace = name; |
|||
node.name = this.jsxParseIdentifier(); |
|||
return this.finishNode(node, "JSXNamespacedName"); |
|||
} |
|||
jsxParseElementName() { |
|||
const startLoc = this.state.startLoc; |
|||
let node = this.jsxParseNamespacedName(); |
|||
if (node.type === "JSXNamespacedName") { |
|||
return node; |
|||
} |
|||
while (this.eat(16)) { |
|||
const newNode = this.startNodeAt(startLoc); |
|||
newNode.object = node; |
|||
newNode.property = this.jsxParseIdentifier(); |
|||
node = this.finishNode(newNode, "JSXMemberExpression"); |
|||
} |
|||
return node; |
|||
} |
|||
jsxParseAttributeValue() { |
|||
let node; |
|||
switch (this.state.type) { |
|||
case 5: |
|||
node = this.startNode(); |
|||
this.setContext(_context.types.brace); |
|||
this.next(); |
|||
node = this.jsxParseExpressionContainer(node, _context.types.j_oTag); |
|||
if (node.expression.type === "JSXEmptyExpression") { |
|||
this.raise(JsxErrors.AttributeIsEmpty, { |
|||
at: node |
|||
}); |
|||
} |
|||
return node; |
|||
case 140: |
|||
case 131: |
|||
return this.parseExprAtom(); |
|||
default: |
|||
throw this.raise(JsxErrors.UnsupportedJsxValue, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
} |
|||
jsxParseEmptyExpression() { |
|||
const node = this.startNodeAt(this.state.lastTokEndLoc); |
|||
return this.finishNodeAt(node, "JSXEmptyExpression", this.state.startLoc); |
|||
} |
|||
jsxParseSpreadChild(node) { |
|||
this.next(); |
|||
node.expression = this.parseExpression(); |
|||
this.setContext(_context.types.j_expr); |
|||
this.state.canStartJSXElement = true; |
|||
this.expect(8); |
|||
return this.finishNode(node, "JSXSpreadChild"); |
|||
} |
|||
jsxParseExpressionContainer(node, previousContext) { |
|||
if (this.match(8)) { |
|||
node.expression = this.jsxParseEmptyExpression(); |
|||
} else { |
|||
const expression = this.parseExpression(); |
|||
; |
|||
node.expression = expression; |
|||
} |
|||
this.setContext(previousContext); |
|||
this.state.canStartJSXElement = true; |
|||
this.expect(8); |
|||
return this.finishNode(node, "JSXExpressionContainer"); |
|||
} |
|||
jsxParseAttribute() { |
|||
const node = this.startNode(); |
|||
if (this.match(5)) { |
|||
this.setContext(_context.types.brace); |
|||
this.next(); |
|||
this.expect(21); |
|||
node.argument = this.parseMaybeAssignAllowIn(); |
|||
this.setContext(_context.types.j_oTag); |
|||
this.state.canStartJSXElement = true; |
|||
this.expect(8); |
|||
return this.finishNode(node, "JSXSpreadAttribute"); |
|||
} |
|||
node.name = this.jsxParseNamespacedName(); |
|||
node.value = this.eat(29) ? this.jsxParseAttributeValue() : null; |
|||
return this.finishNode(node, "JSXAttribute"); |
|||
} |
|||
jsxParseOpeningElementAt(startLoc) { |
|||
const node = this.startNodeAt(startLoc); |
|||
if (this.eat(141)) { |
|||
return this.finishNode(node, "JSXOpeningFragment"); |
|||
} |
|||
node.name = this.jsxParseElementName(); |
|||
return this.jsxParseOpeningElementAfterName(node); |
|||
} |
|||
jsxParseOpeningElementAfterName(node) { |
|||
const attributes = []; |
|||
while (!this.match(56) && !this.match(141)) { |
|||
attributes.push(this.jsxParseAttribute()); |
|||
} |
|||
node.attributes = attributes; |
|||
node.selfClosing = this.eat(56); |
|||
this.expect(141); |
|||
return this.finishNode(node, "JSXOpeningElement"); |
|||
} |
|||
jsxParseClosingElementAt(startLoc) { |
|||
const node = this.startNodeAt(startLoc); |
|||
if (this.eat(141)) { |
|||
return this.finishNode(node, "JSXClosingFragment"); |
|||
} |
|||
node.name = this.jsxParseElementName(); |
|||
this.expect(141); |
|||
return this.finishNode(node, "JSXClosingElement"); |
|||
} |
|||
jsxParseElementAt(startLoc) { |
|||
const node = this.startNodeAt(startLoc); |
|||
const children = []; |
|||
const openingElement = this.jsxParseOpeningElementAt(startLoc); |
|||
let closingElement = null; |
|||
if (!openingElement.selfClosing) { |
|||
contents: for (;;) { |
|||
switch (this.state.type) { |
|||
case 140: |
|||
startLoc = this.state.startLoc; |
|||
this.next(); |
|||
if (this.eat(56)) { |
|||
closingElement = this.jsxParseClosingElementAt(startLoc); |
|||
break contents; |
|||
} |
|||
children.push(this.jsxParseElementAt(startLoc)); |
|||
break; |
|||
case 139: |
|||
children.push(this.parseExprAtom()); |
|||
break; |
|||
case 5: |
|||
{ |
|||
const node = this.startNode(); |
|||
this.setContext(_context.types.brace); |
|||
this.next(); |
|||
if (this.match(21)) { |
|||
children.push(this.jsxParseSpreadChild(node)); |
|||
} else { |
|||
children.push(this.jsxParseExpressionContainer(node, _context.types.j_expr)); |
|||
} |
|||
break; |
|||
} |
|||
default: |
|||
this.unexpected(); |
|||
} |
|||
} |
|||
if (isFragment(openingElement) && !isFragment(closingElement) && closingElement !== null) { |
|||
this.raise(JsxErrors.MissingClosingTagFragment, { |
|||
at: closingElement |
|||
}); |
|||
} else if (!isFragment(openingElement) && isFragment(closingElement)) { |
|||
this.raise(JsxErrors.MissingClosingTagElement, { |
|||
at: closingElement, |
|||
openingTagName: getQualifiedJSXName(openingElement.name) |
|||
}); |
|||
} else if (!isFragment(openingElement) && !isFragment(closingElement)) { |
|||
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) { |
|||
this.raise(JsxErrors.MissingClosingTagElement, { |
|||
at: closingElement, |
|||
openingTagName: getQualifiedJSXName(openingElement.name) |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
if (isFragment(openingElement)) { |
|||
node.openingFragment = openingElement; |
|||
node.closingFragment = closingElement; |
|||
} else { |
|||
node.openingElement = openingElement; |
|||
node.closingElement = closingElement; |
|||
} |
|||
node.children = children; |
|||
if (this.match(47)) { |
|||
throw this.raise(JsxErrors.UnwrappedAdjacentJSXElements, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
return isFragment(openingElement) ? this.finishNode(node, "JSXFragment") : this.finishNode(node, "JSXElement"); |
|||
} |
|||
jsxParseElement() { |
|||
const startLoc = this.state.startLoc; |
|||
this.next(); |
|||
return this.jsxParseElementAt(startLoc); |
|||
} |
|||
setContext(newContext) { |
|||
const { |
|||
context |
|||
} = this.state; |
|||
context[context.length - 1] = newContext; |
|||
} |
|||
parseExprAtom(refExpressionErrors) { |
|||
if (this.match(139)) { |
|||
return this.parseLiteral(this.state.value, "JSXText"); |
|||
} else if (this.match(140)) { |
|||
return this.jsxParseElement(); |
|||
} else if (this.match(47) && this.input.charCodeAt(this.state.pos) !== 33) { |
|||
this.replaceToken(140); |
|||
return this.jsxParseElement(); |
|||
} else { |
|||
return super.parseExprAtom(refExpressionErrors); |
|||
} |
|||
} |
|||
skipSpace() { |
|||
const curContext = this.curContext(); |
|||
if (!curContext.preserveSpace) super.skipSpace(); |
|||
} |
|||
getTokenFromCode(code) { |
|||
const context = this.curContext(); |
|||
if (context === _context.types.j_expr) { |
|||
this.jsxReadToken(); |
|||
return; |
|||
} |
|||
if (context === _context.types.j_oTag || context === _context.types.j_cTag) { |
|||
if ((0, _identifier.isIdentifierStart)(code)) { |
|||
this.jsxReadWord(); |
|||
return; |
|||
} |
|||
if (code === 62) { |
|||
++this.state.pos; |
|||
this.finishToken(141); |
|||
return; |
|||
} |
|||
if ((code === 34 || code === 39) && context === _context.types.j_oTag) { |
|||
this.jsxReadString(code); |
|||
return; |
|||
} |
|||
} |
|||
if (code === 60 && this.state.canStartJSXElement && this.input.charCodeAt(this.state.pos + 1) !== 33) { |
|||
++this.state.pos; |
|||
this.finishToken(140); |
|||
return; |
|||
} |
|||
super.getTokenFromCode(code); |
|||
} |
|||
updateContext(prevType) { |
|||
const { |
|||
context, |
|||
type |
|||
} = this.state; |
|||
if (type === 56 && prevType === 140) { |
|||
context.splice(-2, 2, _context.types.j_cTag); |
|||
this.state.canStartJSXElement = false; |
|||
} else if (type === 140) { |
|||
context.push(_context.types.j_oTag); |
|||
} else if (type === 141) { |
|||
const out = context[context.length - 1]; |
|||
if (out === _context.types.j_oTag && prevType === 56 || out === _context.types.j_cTag) { |
|||
context.pop(); |
|||
this.state.canStartJSXElement = context[context.length - 1] === _context.types.j_expr; |
|||
} else { |
|||
this.setContext(_context.types.j_expr); |
|||
this.state.canStartJSXElement = true; |
|||
} |
|||
} else { |
|||
this.state.canStartJSXElement = (0, _types.tokenComesBeforeExpression)(type); |
|||
} |
|||
} |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=index.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,266 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
const entities = { |
|||
__proto__: null, |
|||
quot: "\u0022", |
|||
amp: "&", |
|||
apos: "\u0027", |
|||
lt: "<", |
|||
gt: ">", |
|||
nbsp: "\u00A0", |
|||
iexcl: "\u00A1", |
|||
cent: "\u00A2", |
|||
pound: "\u00A3", |
|||
curren: "\u00A4", |
|||
yen: "\u00A5", |
|||
brvbar: "\u00A6", |
|||
sect: "\u00A7", |
|||
uml: "\u00A8", |
|||
copy: "\u00A9", |
|||
ordf: "\u00AA", |
|||
laquo: "\u00AB", |
|||
not: "\u00AC", |
|||
shy: "\u00AD", |
|||
reg: "\u00AE", |
|||
macr: "\u00AF", |
|||
deg: "\u00B0", |
|||
plusmn: "\u00B1", |
|||
sup2: "\u00B2", |
|||
sup3: "\u00B3", |
|||
acute: "\u00B4", |
|||
micro: "\u00B5", |
|||
para: "\u00B6", |
|||
middot: "\u00B7", |
|||
cedil: "\u00B8", |
|||
sup1: "\u00B9", |
|||
ordm: "\u00BA", |
|||
raquo: "\u00BB", |
|||
frac14: "\u00BC", |
|||
frac12: "\u00BD", |
|||
frac34: "\u00BE", |
|||
iquest: "\u00BF", |
|||
Agrave: "\u00C0", |
|||
Aacute: "\u00C1", |
|||
Acirc: "\u00C2", |
|||
Atilde: "\u00C3", |
|||
Auml: "\u00C4", |
|||
Aring: "\u00C5", |
|||
AElig: "\u00C6", |
|||
Ccedil: "\u00C7", |
|||
Egrave: "\u00C8", |
|||
Eacute: "\u00C9", |
|||
Ecirc: "\u00CA", |
|||
Euml: "\u00CB", |
|||
Igrave: "\u00CC", |
|||
Iacute: "\u00CD", |
|||
Icirc: "\u00CE", |
|||
Iuml: "\u00CF", |
|||
ETH: "\u00D0", |
|||
Ntilde: "\u00D1", |
|||
Ograve: "\u00D2", |
|||
Oacute: "\u00D3", |
|||
Ocirc: "\u00D4", |
|||
Otilde: "\u00D5", |
|||
Ouml: "\u00D6", |
|||
times: "\u00D7", |
|||
Oslash: "\u00D8", |
|||
Ugrave: "\u00D9", |
|||
Uacute: "\u00DA", |
|||
Ucirc: "\u00DB", |
|||
Uuml: "\u00DC", |
|||
Yacute: "\u00DD", |
|||
THORN: "\u00DE", |
|||
szlig: "\u00DF", |
|||
agrave: "\u00E0", |
|||
aacute: "\u00E1", |
|||
acirc: "\u00E2", |
|||
atilde: "\u00E3", |
|||
auml: "\u00E4", |
|||
aring: "\u00E5", |
|||
aelig: "\u00E6", |
|||
ccedil: "\u00E7", |
|||
egrave: "\u00E8", |
|||
eacute: "\u00E9", |
|||
ecirc: "\u00EA", |
|||
euml: "\u00EB", |
|||
igrave: "\u00EC", |
|||
iacute: "\u00ED", |
|||
icirc: "\u00EE", |
|||
iuml: "\u00EF", |
|||
eth: "\u00F0", |
|||
ntilde: "\u00F1", |
|||
ograve: "\u00F2", |
|||
oacute: "\u00F3", |
|||
ocirc: "\u00F4", |
|||
otilde: "\u00F5", |
|||
ouml: "\u00F6", |
|||
divide: "\u00F7", |
|||
oslash: "\u00F8", |
|||
ugrave: "\u00F9", |
|||
uacute: "\u00FA", |
|||
ucirc: "\u00FB", |
|||
uuml: "\u00FC", |
|||
yacute: "\u00FD", |
|||
thorn: "\u00FE", |
|||
yuml: "\u00FF", |
|||
OElig: "\u0152", |
|||
oelig: "\u0153", |
|||
Scaron: "\u0160", |
|||
scaron: "\u0161", |
|||
Yuml: "\u0178", |
|||
fnof: "\u0192", |
|||
circ: "\u02C6", |
|||
tilde: "\u02DC", |
|||
Alpha: "\u0391", |
|||
Beta: "\u0392", |
|||
Gamma: "\u0393", |
|||
Delta: "\u0394", |
|||
Epsilon: "\u0395", |
|||
Zeta: "\u0396", |
|||
Eta: "\u0397", |
|||
Theta: "\u0398", |
|||
Iota: "\u0399", |
|||
Kappa: "\u039A", |
|||
Lambda: "\u039B", |
|||
Mu: "\u039C", |
|||
Nu: "\u039D", |
|||
Xi: "\u039E", |
|||
Omicron: "\u039F", |
|||
Pi: "\u03A0", |
|||
Rho: "\u03A1", |
|||
Sigma: "\u03A3", |
|||
Tau: "\u03A4", |
|||
Upsilon: "\u03A5", |
|||
Phi: "\u03A6", |
|||
Chi: "\u03A7", |
|||
Psi: "\u03A8", |
|||
Omega: "\u03A9", |
|||
alpha: "\u03B1", |
|||
beta: "\u03B2", |
|||
gamma: "\u03B3", |
|||
delta: "\u03B4", |
|||
epsilon: "\u03B5", |
|||
zeta: "\u03B6", |
|||
eta: "\u03B7", |
|||
theta: "\u03B8", |
|||
iota: "\u03B9", |
|||
kappa: "\u03BA", |
|||
lambda: "\u03BB", |
|||
mu: "\u03BC", |
|||
nu: "\u03BD", |
|||
xi: "\u03BE", |
|||
omicron: "\u03BF", |
|||
pi: "\u03C0", |
|||
rho: "\u03C1", |
|||
sigmaf: "\u03C2", |
|||
sigma: "\u03C3", |
|||
tau: "\u03C4", |
|||
upsilon: "\u03C5", |
|||
phi: "\u03C6", |
|||
chi: "\u03C7", |
|||
psi: "\u03C8", |
|||
omega: "\u03C9", |
|||
thetasym: "\u03D1", |
|||
upsih: "\u03D2", |
|||
piv: "\u03D6", |
|||
ensp: "\u2002", |
|||
emsp: "\u2003", |
|||
thinsp: "\u2009", |
|||
zwnj: "\u200C", |
|||
zwj: "\u200D", |
|||
lrm: "\u200E", |
|||
rlm: "\u200F", |
|||
ndash: "\u2013", |
|||
mdash: "\u2014", |
|||
lsquo: "\u2018", |
|||
rsquo: "\u2019", |
|||
sbquo: "\u201A", |
|||
ldquo: "\u201C", |
|||
rdquo: "\u201D", |
|||
bdquo: "\u201E", |
|||
dagger: "\u2020", |
|||
Dagger: "\u2021", |
|||
bull: "\u2022", |
|||
hellip: "\u2026", |
|||
permil: "\u2030", |
|||
prime: "\u2032", |
|||
Prime: "\u2033", |
|||
lsaquo: "\u2039", |
|||
rsaquo: "\u203A", |
|||
oline: "\u203E", |
|||
frasl: "\u2044", |
|||
euro: "\u20AC", |
|||
image: "\u2111", |
|||
weierp: "\u2118", |
|||
real: "\u211C", |
|||
trade: "\u2122", |
|||
alefsym: "\u2135", |
|||
larr: "\u2190", |
|||
uarr: "\u2191", |
|||
rarr: "\u2192", |
|||
darr: "\u2193", |
|||
harr: "\u2194", |
|||
crarr: "\u21B5", |
|||
lArr: "\u21D0", |
|||
uArr: "\u21D1", |
|||
rArr: "\u21D2", |
|||
dArr: "\u21D3", |
|||
hArr: "\u21D4", |
|||
forall: "\u2200", |
|||
part: "\u2202", |
|||
exist: "\u2203", |
|||
empty: "\u2205", |
|||
nabla: "\u2207", |
|||
isin: "\u2208", |
|||
notin: "\u2209", |
|||
ni: "\u220B", |
|||
prod: "\u220F", |
|||
sum: "\u2211", |
|||
minus: "\u2212", |
|||
lowast: "\u2217", |
|||
radic: "\u221A", |
|||
prop: "\u221D", |
|||
infin: "\u221E", |
|||
ang: "\u2220", |
|||
and: "\u2227", |
|||
or: "\u2228", |
|||
cap: "\u2229", |
|||
cup: "\u222A", |
|||
int: "\u222B", |
|||
there4: "\u2234", |
|||
sim: "\u223C", |
|||
cong: "\u2245", |
|||
asymp: "\u2248", |
|||
ne: "\u2260", |
|||
equiv: "\u2261", |
|||
le: "\u2264", |
|||
ge: "\u2265", |
|||
sub: "\u2282", |
|||
sup: "\u2283", |
|||
nsub: "\u2284", |
|||
sube: "\u2286", |
|||
supe: "\u2287", |
|||
oplus: "\u2295", |
|||
otimes: "\u2297", |
|||
perp: "\u22A5", |
|||
sdot: "\u22C5", |
|||
lceil: "\u2308", |
|||
rceil: "\u2309", |
|||
lfloor: "\u230A", |
|||
rfloor: "\u230B", |
|||
lang: "\u2329", |
|||
rang: "\u232A", |
|||
loz: "\u25CA", |
|||
spades: "\u2660", |
|||
clubs: "\u2663", |
|||
hearts: "\u2665", |
|||
diams: "\u2666" |
|||
}; |
|||
var _default = entities; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=xhtml.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,196 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _types = require("../tokenizer/types"); |
|||
var _parseError = require("../parse-error"); |
|||
const PlaceholderErrors = (0, _parseError.ParseErrorEnum)`placeholders`({ |
|||
ClassNameIsRequired: "A class name is required.", |
|||
UnexpectedSpace: "Unexpected space in placeholder." |
|||
}); |
|||
var _default = superClass => class PlaceholdersParserMixin extends superClass { |
|||
parsePlaceholder(expectedNode) { |
|||
if (this.match(142)) { |
|||
const node = this.startNode(); |
|||
this.next(); |
|||
this.assertNoSpace(); |
|||
node.name = super.parseIdentifier(true); |
|||
this.assertNoSpace(); |
|||
this.expect(142); |
|||
return this.finishPlaceholder(node, expectedNode); |
|||
} |
|||
} |
|||
finishPlaceholder(node, expectedNode) { |
|||
const isFinished = !!(node.expectedNode && node.type === "Placeholder"); |
|||
node.expectedNode = expectedNode; |
|||
return isFinished ? node : this.finishNode(node, "Placeholder"); |
|||
} |
|||
getTokenFromCode(code) { |
|||
if (code === 37 && this.input.charCodeAt(this.state.pos + 1) === 37) { |
|||
this.finishOp(142, 2); |
|||
} else { |
|||
super.getTokenFromCode(code); |
|||
} |
|||
} |
|||
parseExprAtom(refExpressionErrors) { |
|||
return this.parsePlaceholder("Expression") || super.parseExprAtom(refExpressionErrors); |
|||
} |
|||
parseIdentifier(liberal) { |
|||
return this.parsePlaceholder("Identifier") || super.parseIdentifier(liberal); |
|||
} |
|||
checkReservedWord(word, startLoc, checkKeywords, isBinding) { |
|||
if (word !== undefined) { |
|||
super.checkReservedWord(word, startLoc, checkKeywords, isBinding); |
|||
} |
|||
} |
|||
parseBindingAtom() { |
|||
return this.parsePlaceholder("Pattern") || super.parseBindingAtom(); |
|||
} |
|||
isValidLVal(type, isParenthesized, binding) { |
|||
return type === "Placeholder" || super.isValidLVal(type, isParenthesized, binding); |
|||
} |
|||
toAssignable(node, isLHS) { |
|||
if (node && node.type === "Placeholder" && node.expectedNode === "Expression") { |
|||
node.expectedNode = "Pattern"; |
|||
} else { |
|||
super.toAssignable(node, isLHS); |
|||
} |
|||
} |
|||
chStartsBindingIdentifier(ch, pos) { |
|||
if (super.chStartsBindingIdentifier(ch, pos)) { |
|||
return true; |
|||
} |
|||
const nextToken = this.lookahead(); |
|||
if (nextToken.type === 142) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
verifyBreakContinue(node, isBreak) { |
|||
if (node.label && node.label.type === "Placeholder") return; |
|||
super.verifyBreakContinue(node, isBreak); |
|||
} |
|||
parseExpressionStatement(node, expr) { |
|||
if (expr.type !== "Placeholder" || expr.extra && expr.extra.parenthesized) { |
|||
return super.parseExpressionStatement(node, expr); |
|||
} |
|||
if (this.match(14)) { |
|||
const stmt = node; |
|||
stmt.label = this.finishPlaceholder(expr, "Identifier"); |
|||
this.next(); |
|||
stmt.body = super.parseStatementOrSloppyAnnexBFunctionDeclaration(); |
|||
return this.finishNode(stmt, "LabeledStatement"); |
|||
} |
|||
this.semicolon(); |
|||
node.name = expr.name; |
|||
return this.finishPlaceholder(node, "Statement"); |
|||
} |
|||
parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse) { |
|||
return this.parsePlaceholder("BlockStatement") || super.parseBlock(allowDirectives, createNewLexicalScope, afterBlockParse); |
|||
} |
|||
parseFunctionId(requireId) { |
|||
return this.parsePlaceholder("Identifier") || super.parseFunctionId(requireId); |
|||
} |
|||
parseClass(node, isStatement, optionalId) { |
|||
const type = isStatement ? "ClassDeclaration" : "ClassExpression"; |
|||
this.next(); |
|||
const oldStrict = this.state.strict; |
|||
const placeholder = this.parsePlaceholder("Identifier"); |
|||
if (placeholder) { |
|||
if (this.match(81) || this.match(142) || this.match(5)) { |
|||
node.id = placeholder; |
|||
} else if (optionalId || !isStatement) { |
|||
node.id = null; |
|||
node.body = this.finishPlaceholder(placeholder, "ClassBody"); |
|||
return this.finishNode(node, type); |
|||
} else { |
|||
throw this.raise(PlaceholderErrors.ClassNameIsRequired, { |
|||
at: this.state.startLoc |
|||
}); |
|||
} |
|||
} else { |
|||
this.parseClassId(node, isStatement, optionalId); |
|||
} |
|||
super.parseClassSuper(node); |
|||
node.body = this.parsePlaceholder("ClassBody") || super.parseClassBody(!!node.superClass, oldStrict); |
|||
return this.finishNode(node, type); |
|||
} |
|||
parseExport(node, decorators) { |
|||
const placeholder = this.parsePlaceholder("Identifier"); |
|||
if (!placeholder) return super.parseExport(node, decorators); |
|||
if (!this.isContextual(97) && !this.match(12)) { |
|||
node.specifiers = []; |
|||
node.source = null; |
|||
node.declaration = this.finishPlaceholder(placeholder, "Declaration"); |
|||
return this.finishNode(node, "ExportNamedDeclaration"); |
|||
} |
|||
this.expectPlugin("exportDefaultFrom"); |
|||
const specifier = this.startNode(); |
|||
specifier.exported = placeholder; |
|||
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; |
|||
return super.parseExport(node, decorators); |
|||
} |
|||
isExportDefaultSpecifier() { |
|||
if (this.match(65)) { |
|||
const next = this.nextTokenStart(); |
|||
if (this.isUnparsedContextual(next, "from")) { |
|||
if (this.input.startsWith((0, _types.tokenLabelName)(142), this.nextTokenStartSince(next + 4))) { |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
return super.isExportDefaultSpecifier(); |
|||
} |
|||
maybeParseExportDefaultSpecifier(node) { |
|||
if (node.specifiers && node.specifiers.length > 0) { |
|||
return true; |
|||
} |
|||
return super.maybeParseExportDefaultSpecifier(node); |
|||
} |
|||
checkExport(node) { |
|||
const { |
|||
specifiers |
|||
} = node; |
|||
if (specifiers != null && specifiers.length) { |
|||
node.specifiers = specifiers.filter(node => node.exported.type === "Placeholder"); |
|||
} |
|||
super.checkExport(node); |
|||
node.specifiers = specifiers; |
|||
} |
|||
parseImport(node) { |
|||
const placeholder = this.parsePlaceholder("Identifier"); |
|||
if (!placeholder) return super.parseImport(node); |
|||
node.specifiers = []; |
|||
if (!this.isContextual(97) && !this.match(12)) { |
|||
node.source = this.finishPlaceholder(placeholder, "StringLiteral"); |
|||
this.semicolon(); |
|||
return this.finishNode(node, "ImportDeclaration"); |
|||
} |
|||
const specifier = this.startNodeAtNode(placeholder); |
|||
specifier.local = placeholder; |
|||
node.specifiers.push(this.finishNode(specifier, "ImportDefaultSpecifier")); |
|||
if (this.eat(12)) { |
|||
const hasStarImport = this.maybeParseStarImportSpecifier(node); |
|||
if (!hasStarImport) this.parseNamedImportSpecifiers(node); |
|||
} |
|||
this.expectContextual(97); |
|||
node.source = this.parseImportSource(); |
|||
this.semicolon(); |
|||
return this.finishNode(node, "ImportDeclaration"); |
|||
} |
|||
parseImportSource() { |
|||
return this.parsePlaceholder("StringLiteral") || super.parseImportSource(); |
|||
} |
|||
assertNoSpace() { |
|||
if (this.state.start > this.state.lastTokEndLoc.index) { |
|||
this.raise(PlaceholderErrors.UnexpectedSpace, { |
|||
at: this.state.lastTokEndLoc |
|||
}); |
|||
} |
|||
} |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=placeholders.js.map
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,119 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _scope = require("../../util/scope"); |
|||
var _scopeflags = require("../../util/scopeflags"); |
|||
var _parseError = require("../../parse-error"); |
|||
class TypeScriptScope extends _scope.Scope { |
|||
constructor(...args) { |
|||
super(...args); |
|||
this.types = new Set(); |
|||
this.enums = new Set(); |
|||
this.constEnums = new Set(); |
|||
this.classes = new Set(); |
|||
this.exportOnlyBindings = new Set(); |
|||
} |
|||
} |
|||
class TypeScriptScopeHandler extends _scope.default { |
|||
constructor(...args) { |
|||
super(...args); |
|||
this.importsStack = []; |
|||
} |
|||
createScope(flags) { |
|||
this.importsStack.push(new Set()); |
|||
return new TypeScriptScope(flags); |
|||
} |
|||
enter(flags) { |
|||
if (flags == _scopeflags.SCOPE_TS_MODULE) { |
|||
this.importsStack.push(new Set()); |
|||
} |
|||
super.enter(flags); |
|||
} |
|||
exit() { |
|||
const flags = super.exit(); |
|||
if (flags == _scopeflags.SCOPE_TS_MODULE) { |
|||
this.importsStack.pop(); |
|||
} |
|||
return flags; |
|||
} |
|||
hasImport(name, allowShadow) { |
|||
const len = this.importsStack.length; |
|||
if (this.importsStack[len - 1].has(name)) { |
|||
return true; |
|||
} |
|||
if (!allowShadow && len > 1) { |
|||
for (let i = 0; i < len - 1; i++) { |
|||
if (this.importsStack[i].has(name)) return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
declareName(name, bindingType, loc) { |
|||
if (bindingType & _scopeflags.BIND_FLAGS_TS_IMPORT) { |
|||
if (this.hasImport(name, true)) { |
|||
this.parser.raise(_parseError.Errors.VarRedeclaration, { |
|||
at: loc, |
|||
identifierName: name |
|||
}); |
|||
} |
|||
this.importsStack[this.importsStack.length - 1].add(name); |
|||
return; |
|||
} |
|||
const scope = this.currentScope(); |
|||
if (bindingType & _scopeflags.BIND_FLAGS_TS_EXPORT_ONLY) { |
|||
this.maybeExportDefined(scope, name); |
|||
scope.exportOnlyBindings.add(name); |
|||
return; |
|||
} |
|||
super.declareName(name, bindingType, loc); |
|||
if (bindingType & _scopeflags.BIND_KIND_TYPE) { |
|||
if (!(bindingType & _scopeflags.BIND_KIND_VALUE)) { |
|||
this.checkRedeclarationInScope(scope, name, bindingType, loc); |
|||
this.maybeExportDefined(scope, name); |
|||
} |
|||
scope.types.add(name); |
|||
} |
|||
if (bindingType & _scopeflags.BIND_FLAGS_TS_ENUM) scope.enums.add(name); |
|||
if (bindingType & _scopeflags.BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.add(name); |
|||
if (bindingType & _scopeflags.BIND_FLAGS_CLASS) scope.classes.add(name); |
|||
} |
|||
isRedeclaredInScope(scope, name, bindingType) { |
|||
if (scope.enums.has(name)) { |
|||
if (bindingType & _scopeflags.BIND_FLAGS_TS_ENUM) { |
|||
const isConst = !!(bindingType & _scopeflags.BIND_FLAGS_TS_CONST_ENUM); |
|||
const wasConst = scope.constEnums.has(name); |
|||
return isConst !== wasConst; |
|||
} |
|||
return true; |
|||
} |
|||
if (bindingType & _scopeflags.BIND_FLAGS_CLASS && scope.classes.has(name)) { |
|||
if (scope.lexical.has(name)) { |
|||
return !!(bindingType & _scopeflags.BIND_KIND_VALUE); |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
if (bindingType & _scopeflags.BIND_KIND_TYPE && scope.types.has(name)) { |
|||
return true; |
|||
} |
|||
return super.isRedeclaredInScope(scope, name, bindingType); |
|||
} |
|||
checkLocalExport(id) { |
|||
const { |
|||
name |
|||
} = id; |
|||
if (this.hasImport(name)) return; |
|||
const len = this.scopeStack.length; |
|||
for (let i = len - 1; i >= 0; i--) { |
|||
const scope = this.scopeStack[i]; |
|||
if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return; |
|||
} |
|||
super.checkLocalExport(id); |
|||
} |
|||
} |
|||
exports.default = TypeScriptScopeHandler; |
|||
|
|||
//# sourceMappingURL=scope.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,31 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _types = require("../tokenizer/types"); |
|||
var _default = superClass => class V8IntrinsicMixin extends superClass { |
|||
parseV8Intrinsic() { |
|||
if (this.match(54)) { |
|||
const v8IntrinsicStartLoc = this.state.startLoc; |
|||
const node = this.startNode(); |
|||
this.next(); |
|||
if ((0, _types.tokenIsIdentifier)(this.state.type)) { |
|||
const name = this.parseIdentifierName(); |
|||
const identifier = this.createIdentifier(node, name); |
|||
identifier.type = "V8IntrinsicIdentifier"; |
|||
if (this.match(10)) { |
|||
return identifier; |
|||
} |
|||
} |
|||
this.unexpected(v8IntrinsicStartLoc); |
|||
} |
|||
} |
|||
parseExprAtom(refExpressionErrors) { |
|||
return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors); |
|||
} |
|||
}; |
|||
exports.default = _default; |
|||
|
|||
//# sourceMappingURL=v8intrinsic.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_types","require","_default","superClass","V8IntrinsicMixin","parseV8Intrinsic","match","v8IntrinsicStartLoc","state","startLoc","node","startNode","next","tokenIsIdentifier","type","name","parseIdentifierName","identifier","createIdentifier","unexpected","parseExprAtom","refExpressionErrors","exports","default"],"sources":["../../src/plugins/v8intrinsic.ts"],"sourcesContent":["import type Parser from \"../parser\";\nimport { tokenIsIdentifier, tt } from \"../tokenizer/types\";\nimport type * as N from \"../types\";\nimport type { ExpressionErrors } from \"../parser/util\";\n\nexport default (superClass: typeof Parser) =>\n class V8IntrinsicMixin extends superClass implements Parser {\n parseV8Intrinsic(): N.Expression {\n if (this.match(tt.modulo)) {\n const v8IntrinsicStartLoc = this.state.startLoc;\n // let the `loc` of Identifier starts from `%`\n const node = this.startNode<N.Identifier>();\n this.next(); // eat '%'\n if (tokenIsIdentifier(this.state.type)) {\n const name = this.parseIdentifierName();\n const identifier = this.createIdentifier(node, name);\n // @ts-expect-error: avoid mutating AST types\n identifier.type = \"V8IntrinsicIdentifier\";\n if (this.match(tt.parenL)) {\n return identifier;\n }\n }\n this.unexpected(v8IntrinsicStartLoc);\n }\n }\n\n /* ============================================================ *\n * parser/expression.js *\n * ============================================================ */\n\n parseExprAtom(refExpressionErrors?: ExpressionErrors | null): N.Expression {\n return (\n this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors)\n );\n }\n };\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAA2D,IAAAC,QAAA,GAI3CC,UAAyB,IACvC,MAAMC,gBAAgB,SAASD,UAAU,CAAmB;EAC1DE,gBAAgBA,CAAA,EAAiB;IAC/B,IAAI,IAAI,CAACC,KAAK,IAAW,EAAE;MACzB,MAAMC,mBAAmB,GAAG,IAAI,CAACC,KAAK,CAACC,QAAQ;MAE/C,MAAMC,IAAI,GAAG,IAAI,CAACC,SAAS,EAAgB;MAC3C,IAAI,CAACC,IAAI,EAAE;MACX,IAAI,IAAAC,wBAAiB,EAAC,IAAI,CAACL,KAAK,CAACM,IAAI,CAAC,EAAE;QACtC,MAAMC,IAAI,GAAG,IAAI,CAACC,mBAAmB,EAAE;QACvC,MAAMC,UAAU,GAAG,IAAI,CAACC,gBAAgB,CAACR,IAAI,EAAEK,IAAI,CAAC;QAEpDE,UAAU,CAACH,IAAI,GAAG,uBAAuB;QACzC,IAAI,IAAI,CAACR,KAAK,IAAW,EAAE;UACzB,OAAOW,UAAU;QACnB;MACF;MACA,IAAI,CAACE,UAAU,CAACZ,mBAAmB,CAAC;IACtC;EACF;EAMAa,aAAaA,CAACC,mBAA6C,EAAgB;IACzE,OACE,IAAI,CAAChB,gBAAgB,EAAE,IAAI,KAAK,CAACe,aAAa,CAACC,mBAAmB,CAAC;EAEvE;AACF,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAArB,QAAA"} |
|||
@ -1,27 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.types = exports.TokContext = void 0; |
|||
class TokContext { |
|||
constructor(token, preserveSpace) { |
|||
this.token = void 0; |
|||
this.preserveSpace = void 0; |
|||
this.token = token; |
|||
this.preserveSpace = !!preserveSpace; |
|||
} |
|||
} |
|||
exports.TokContext = TokContext; |
|||
const types = { |
|||
brace: new TokContext("{"), |
|||
j_oTag: new TokContext("<tag"), |
|||
j_cTag: new TokContext("</tag"), |
|||
j_expr: new TokContext("<tag>...</tag>", true) |
|||
}; |
|||
exports.types = types; |
|||
{ |
|||
types.template = new TokContext("`", true); |
|||
} |
|||
|
|||
//# sourceMappingURL=context.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["TokContext","constructor","token","preserveSpace","exports","types","brace","j_oTag","j_cTag","j_expr","template"],"sources":["../../src/tokenizer/context.ts"],"sourcesContent":["// The token context is used in JSX plugin to track\n// jsx tag / jsx text / normal JavaScript expression\n\nexport class TokContext {\n constructor(token: string, preserveSpace?: boolean) {\n this.token = token;\n this.preserveSpace = !!preserveSpace;\n }\n\n token: string;\n preserveSpace: boolean;\n}\n\nconst types: {\n [key: string]: TokContext;\n} = {\n brace: new TokContext(\"{\"), // normal JavaScript expression\n j_oTag: new TokContext(\"<tag\"), // JSX opening tag\n j_cTag: new TokContext(\"</tag\"), // JSX closing tag\n j_expr: new TokContext(\"<tag>...</tag>\", true), // JSX expressions\n};\n\nif (!process.env.BABEL_8_BREAKING) {\n types.template = new TokContext(\"`\", true);\n}\n\nexport { types };\n"],"mappings":";;;;;;AAGO,MAAMA,UAAU,CAAC;EACtBC,WAAWA,CAACC,KAAa,EAAEC,aAAuB,EAAE;IAAA,KAKpDD,KAAK;IAAA,KACLC,aAAa;IALX,IAAI,CAACD,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,aAAa,GAAG,CAAC,CAACA,aAAa;EACtC;AAIF;AAACC,OAAA,CAAAJ,UAAA,GAAAA,UAAA;AAED,MAAMK,KAEL,GAAG;EACFC,KAAK,EAAE,IAAIN,UAAU,CAAC,GAAG,CAAC;EAC1BO,MAAM,EAAE,IAAIP,UAAU,CAAC,MAAM,CAAC;EAC9BQ,MAAM,EAAE,IAAIR,UAAU,CAAC,OAAO,CAAC;EAC/BS,MAAM,EAAE,IAAIT,UAAU,CAAC,gBAAgB,EAAE,IAAI;AAC/C,CAAC;AAACI,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAEiC;EACjCA,KAAK,CAACK,QAAQ,GAAG,IAAIV,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC;AAC5C"} |
|||
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,82 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
var _location = require("../util/location"); |
|||
var _context = require("./context"); |
|||
var _types = require("./types"); |
|||
class State { |
|||
constructor() { |
|||
this.strict = void 0; |
|||
this.curLine = void 0; |
|||
this.lineStart = void 0; |
|||
this.startLoc = void 0; |
|||
this.endLoc = void 0; |
|||
this.errors = []; |
|||
this.potentialArrowAt = -1; |
|||
this.noArrowAt = []; |
|||
this.noArrowParamsConversionAt = []; |
|||
this.maybeInArrowParameters = false; |
|||
this.inType = false; |
|||
this.noAnonFunctionType = false; |
|||
this.hasFlowComment = false; |
|||
this.isAmbientContext = false; |
|||
this.inAbstractClass = false; |
|||
this.inDisallowConditionalTypesContext = false; |
|||
this.topicContext = { |
|||
maxNumOfResolvableTopics: 0, |
|||
maxTopicIndex: null |
|||
}; |
|||
this.soloAwait = false; |
|||
this.inFSharpPipelineDirectBody = false; |
|||
this.labels = []; |
|||
this.comments = []; |
|||
this.commentStack = []; |
|||
this.pos = 0; |
|||
this.type = 137; |
|||
this.value = null; |
|||
this.start = 0; |
|||
this.end = 0; |
|||
this.lastTokEndLoc = null; |
|||
this.lastTokStartLoc = null; |
|||
this.lastTokStart = 0; |
|||
this.context = [_context.types.brace]; |
|||
this.canStartJSXElement = true; |
|||
this.containsEsc = false; |
|||
this.firstInvalidTemplateEscapePos = null; |
|||
this.strictErrors = new Map(); |
|||
this.tokensLength = 0; |
|||
} |
|||
init({ |
|||
strictMode, |
|||
sourceType, |
|||
startLine, |
|||
startColumn |
|||
}) { |
|||
this.strict = strictMode === false ? false : strictMode === true ? true : sourceType === "module"; |
|||
this.curLine = startLine; |
|||
this.lineStart = -startColumn; |
|||
this.startLoc = this.endLoc = new _location.Position(startLine, startColumn, 0); |
|||
} |
|||
curPosition() { |
|||
return new _location.Position(this.curLine, this.pos - this.lineStart, this.pos); |
|||
} |
|||
clone(skipArrays) { |
|||
const state = new State(); |
|||
const keys = Object.keys(this); |
|||
for (let i = 0, length = keys.length; i < length; i++) { |
|||
const key = keys[i]; |
|||
let val = this[key]; |
|||
if (!skipArrays && Array.isArray(val)) { |
|||
val = val.slice(); |
|||
} |
|||
state[key] = val; |
|||
} |
|||
return state; |
|||
} |
|||
} |
|||
exports.default = State; |
|||
|
|||
//# sourceMappingURL=state.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,586 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.ExportedTokenType = void 0; |
|||
exports.getExportedToken = getExportedToken; |
|||
exports.isTokenType = isTokenType; |
|||
exports.keywords = void 0; |
|||
exports.tokenCanStartExpression = tokenCanStartExpression; |
|||
exports.tokenComesBeforeExpression = tokenComesBeforeExpression; |
|||
exports.tokenIsAssignment = tokenIsAssignment; |
|||
exports.tokenIsBinaryOperator = tokenIsBinaryOperator; |
|||
exports.tokenIsFlowInterfaceOrTypeOrOpaque = tokenIsFlowInterfaceOrTypeOrOpaque; |
|||
exports.tokenIsIdentifier = tokenIsIdentifier; |
|||
exports.tokenIsKeyword = tokenIsKeyword; |
|||
exports.tokenIsKeywordOrIdentifier = tokenIsKeywordOrIdentifier; |
|||
exports.tokenIsLiteralPropertyName = tokenIsLiteralPropertyName; |
|||
exports.tokenIsLoop = tokenIsLoop; |
|||
exports.tokenIsOperator = tokenIsOperator; |
|||
exports.tokenIsPostfix = tokenIsPostfix; |
|||
exports.tokenIsPrefix = tokenIsPrefix; |
|||
exports.tokenIsRightAssociative = tokenIsRightAssociative; |
|||
exports.tokenIsTSDeclarationStart = tokenIsTSDeclarationStart; |
|||
exports.tokenIsTSTypeOperator = tokenIsTSTypeOperator; |
|||
exports.tokenIsTemplate = tokenIsTemplate; |
|||
exports.tokenKeywordOrIdentifierIsKeyword = tokenKeywordOrIdentifierIsKeyword; |
|||
exports.tokenLabelName = tokenLabelName; |
|||
exports.tokenOperatorPrecedence = tokenOperatorPrecedence; |
|||
exports.tt = exports.tokenTypes = void 0; |
|||
var _context = require("./context"); |
|||
const beforeExpr = true; |
|||
const startsExpr = true; |
|||
const isLoop = true; |
|||
const isAssign = true; |
|||
const prefix = true; |
|||
const postfix = true; |
|||
class ExportedTokenType { |
|||
constructor(label, conf = {}) { |
|||
this.label = void 0; |
|||
this.keyword = void 0; |
|||
this.beforeExpr = void 0; |
|||
this.startsExpr = void 0; |
|||
this.rightAssociative = void 0; |
|||
this.isLoop = void 0; |
|||
this.isAssign = void 0; |
|||
this.prefix = void 0; |
|||
this.postfix = void 0; |
|||
this.binop = void 0; |
|||
this.label = label; |
|||
this.keyword = conf.keyword; |
|||
this.beforeExpr = !!conf.beforeExpr; |
|||
this.startsExpr = !!conf.startsExpr; |
|||
this.rightAssociative = !!conf.rightAssociative; |
|||
this.isLoop = !!conf.isLoop; |
|||
this.isAssign = !!conf.isAssign; |
|||
this.prefix = !!conf.prefix; |
|||
this.postfix = !!conf.postfix; |
|||
this.binop = conf.binop != null ? conf.binop : null; |
|||
{ |
|||
this.updateContext = null; |
|||
} |
|||
} |
|||
} |
|||
exports.ExportedTokenType = ExportedTokenType; |
|||
const keywords = new Map(); |
|||
exports.keywords = keywords; |
|||
function createKeyword(name, options = {}) { |
|||
options.keyword = name; |
|||
const token = createToken(name, options); |
|||
keywords.set(name, token); |
|||
return token; |
|||
} |
|||
function createBinop(name, binop) { |
|||
return createToken(name, { |
|||
beforeExpr, |
|||
binop |
|||
}); |
|||
} |
|||
let tokenTypeCounter = -1; |
|||
const tokenTypes = []; |
|||
exports.tokenTypes = tokenTypes; |
|||
const tokenLabels = []; |
|||
const tokenBinops = []; |
|||
const tokenBeforeExprs = []; |
|||
const tokenStartsExprs = []; |
|||
const tokenPrefixes = []; |
|||
function createToken(name, options = {}) { |
|||
var _options$binop, _options$beforeExpr, _options$startsExpr, _options$prefix; |
|||
++tokenTypeCounter; |
|||
tokenLabels.push(name); |
|||
tokenBinops.push((_options$binop = options.binop) != null ? _options$binop : -1); |
|||
tokenBeforeExprs.push((_options$beforeExpr = options.beforeExpr) != null ? _options$beforeExpr : false); |
|||
tokenStartsExprs.push((_options$startsExpr = options.startsExpr) != null ? _options$startsExpr : false); |
|||
tokenPrefixes.push((_options$prefix = options.prefix) != null ? _options$prefix : false); |
|||
tokenTypes.push(new ExportedTokenType(name, options)); |
|||
return tokenTypeCounter; |
|||
} |
|||
function createKeywordLike(name, options = {}) { |
|||
var _options$binop2, _options$beforeExpr2, _options$startsExpr2, _options$prefix2; |
|||
++tokenTypeCounter; |
|||
keywords.set(name, tokenTypeCounter); |
|||
tokenLabels.push(name); |
|||
tokenBinops.push((_options$binop2 = options.binop) != null ? _options$binop2 : -1); |
|||
tokenBeforeExprs.push((_options$beforeExpr2 = options.beforeExpr) != null ? _options$beforeExpr2 : false); |
|||
tokenStartsExprs.push((_options$startsExpr2 = options.startsExpr) != null ? _options$startsExpr2 : false); |
|||
tokenPrefixes.push((_options$prefix2 = options.prefix) != null ? _options$prefix2 : false); |
|||
tokenTypes.push(new ExportedTokenType("name", options)); |
|||
return tokenTypeCounter; |
|||
} |
|||
const tt = { |
|||
bracketL: createToken("[", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
bracketHashL: createToken("#[", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
bracketBarL: createToken("[|", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
bracketR: createToken("]"), |
|||
bracketBarR: createToken("|]"), |
|||
braceL: createToken("{", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
braceBarL: createToken("{|", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
braceHashL: createToken("#{", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
braceR: createToken("}"), |
|||
braceBarR: createToken("|}"), |
|||
parenL: createToken("(", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
parenR: createToken(")"), |
|||
comma: createToken(",", { |
|||
beforeExpr |
|||
}), |
|||
semi: createToken(";", { |
|||
beforeExpr |
|||
}), |
|||
colon: createToken(":", { |
|||
beforeExpr |
|||
}), |
|||
doubleColon: createToken("::", { |
|||
beforeExpr |
|||
}), |
|||
dot: createToken("."), |
|||
question: createToken("?", { |
|||
beforeExpr |
|||
}), |
|||
questionDot: createToken("?."), |
|||
arrow: createToken("=>", { |
|||
beforeExpr |
|||
}), |
|||
template: createToken("template"), |
|||
ellipsis: createToken("...", { |
|||
beforeExpr |
|||
}), |
|||
backQuote: createToken("`", { |
|||
startsExpr |
|||
}), |
|||
dollarBraceL: createToken("${", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
templateTail: createToken("...`", { |
|||
startsExpr |
|||
}), |
|||
templateNonTail: createToken("...${", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
at: createToken("@"), |
|||
hash: createToken("#", { |
|||
startsExpr |
|||
}), |
|||
interpreterDirective: createToken("#!..."), |
|||
eq: createToken("=", { |
|||
beforeExpr, |
|||
isAssign |
|||
}), |
|||
assign: createToken("_=", { |
|||
beforeExpr, |
|||
isAssign |
|||
}), |
|||
slashAssign: createToken("_=", { |
|||
beforeExpr, |
|||
isAssign |
|||
}), |
|||
xorAssign: createToken("_=", { |
|||
beforeExpr, |
|||
isAssign |
|||
}), |
|||
moduloAssign: createToken("_=", { |
|||
beforeExpr, |
|||
isAssign |
|||
}), |
|||
incDec: createToken("++/--", { |
|||
prefix, |
|||
postfix, |
|||
startsExpr |
|||
}), |
|||
bang: createToken("!", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
tilde: createToken("~", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
doubleCaret: createToken("^^", { |
|||
startsExpr |
|||
}), |
|||
doubleAt: createToken("@@", { |
|||
startsExpr |
|||
}), |
|||
pipeline: createBinop("|>", 0), |
|||
nullishCoalescing: createBinop("??", 1), |
|||
logicalOR: createBinop("||", 1), |
|||
logicalAND: createBinop("&&", 2), |
|||
bitwiseOR: createBinop("|", 3), |
|||
bitwiseXOR: createBinop("^", 4), |
|||
bitwiseAND: createBinop("&", 5), |
|||
equality: createBinop("==/!=/===/!==", 6), |
|||
lt: createBinop("</>/<=/>=", 7), |
|||
gt: createBinop("</>/<=/>=", 7), |
|||
relational: createBinop("</>/<=/>=", 7), |
|||
bitShift: createBinop("<</>>/>>>", 8), |
|||
bitShiftL: createBinop("<</>>/>>>", 8), |
|||
bitShiftR: createBinop("<</>>/>>>", 8), |
|||
plusMin: createToken("+/-", { |
|||
beforeExpr, |
|||
binop: 9, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
modulo: createToken("%", { |
|||
binop: 10, |
|||
startsExpr |
|||
}), |
|||
star: createToken("*", { |
|||
binop: 10 |
|||
}), |
|||
slash: createBinop("/", 10), |
|||
exponent: createToken("**", { |
|||
beforeExpr, |
|||
binop: 11, |
|||
rightAssociative: true |
|||
}), |
|||
_in: createKeyword("in", { |
|||
beforeExpr, |
|||
binop: 7 |
|||
}), |
|||
_instanceof: createKeyword("instanceof", { |
|||
beforeExpr, |
|||
binop: 7 |
|||
}), |
|||
_break: createKeyword("break"), |
|||
_case: createKeyword("case", { |
|||
beforeExpr |
|||
}), |
|||
_catch: createKeyword("catch"), |
|||
_continue: createKeyword("continue"), |
|||
_debugger: createKeyword("debugger"), |
|||
_default: createKeyword("default", { |
|||
beforeExpr |
|||
}), |
|||
_else: createKeyword("else", { |
|||
beforeExpr |
|||
}), |
|||
_finally: createKeyword("finally"), |
|||
_function: createKeyword("function", { |
|||
startsExpr |
|||
}), |
|||
_if: createKeyword("if"), |
|||
_return: createKeyword("return", { |
|||
beforeExpr |
|||
}), |
|||
_switch: createKeyword("switch"), |
|||
_throw: createKeyword("throw", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
_try: createKeyword("try"), |
|||
_var: createKeyword("var"), |
|||
_const: createKeyword("const"), |
|||
_with: createKeyword("with"), |
|||
_new: createKeyword("new", { |
|||
beforeExpr, |
|||
startsExpr |
|||
}), |
|||
_this: createKeyword("this", { |
|||
startsExpr |
|||
}), |
|||
_super: createKeyword("super", { |
|||
startsExpr |
|||
}), |
|||
_class: createKeyword("class", { |
|||
startsExpr |
|||
}), |
|||
_extends: createKeyword("extends", { |
|||
beforeExpr |
|||
}), |
|||
_export: createKeyword("export"), |
|||
_import: createKeyword("import", { |
|||
startsExpr |
|||
}), |
|||
_null: createKeyword("null", { |
|||
startsExpr |
|||
}), |
|||
_true: createKeyword("true", { |
|||
startsExpr |
|||
}), |
|||
_false: createKeyword("false", { |
|||
startsExpr |
|||
}), |
|||
_typeof: createKeyword("typeof", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
_void: createKeyword("void", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
_delete: createKeyword("delete", { |
|||
beforeExpr, |
|||
prefix, |
|||
startsExpr |
|||
}), |
|||
_do: createKeyword("do", { |
|||
isLoop, |
|||
beforeExpr |
|||
}), |
|||
_for: createKeyword("for", { |
|||
isLoop |
|||
}), |
|||
_while: createKeyword("while", { |
|||
isLoop |
|||
}), |
|||
_as: createKeywordLike("as", { |
|||
startsExpr |
|||
}), |
|||
_assert: createKeywordLike("assert", { |
|||
startsExpr |
|||
}), |
|||
_async: createKeywordLike("async", { |
|||
startsExpr |
|||
}), |
|||
_await: createKeywordLike("await", { |
|||
startsExpr |
|||
}), |
|||
_from: createKeywordLike("from", { |
|||
startsExpr |
|||
}), |
|||
_get: createKeywordLike("get", { |
|||
startsExpr |
|||
}), |
|||
_let: createKeywordLike("let", { |
|||
startsExpr |
|||
}), |
|||
_meta: createKeywordLike("meta", { |
|||
startsExpr |
|||
}), |
|||
_of: createKeywordLike("of", { |
|||
startsExpr |
|||
}), |
|||
_sent: createKeywordLike("sent", { |
|||
startsExpr |
|||
}), |
|||
_set: createKeywordLike("set", { |
|||
startsExpr |
|||
}), |
|||
_static: createKeywordLike("static", { |
|||
startsExpr |
|||
}), |
|||
_using: createKeywordLike("using", { |
|||
startsExpr |
|||
}), |
|||
_yield: createKeywordLike("yield", { |
|||
startsExpr |
|||
}), |
|||
_asserts: createKeywordLike("asserts", { |
|||
startsExpr |
|||
}), |
|||
_checks: createKeywordLike("checks", { |
|||
startsExpr |
|||
}), |
|||
_exports: createKeywordLike("exports", { |
|||
startsExpr |
|||
}), |
|||
_global: createKeywordLike("global", { |
|||
startsExpr |
|||
}), |
|||
_implements: createKeywordLike("implements", { |
|||
startsExpr |
|||
}), |
|||
_intrinsic: createKeywordLike("intrinsic", { |
|||
startsExpr |
|||
}), |
|||
_infer: createKeywordLike("infer", { |
|||
startsExpr |
|||
}), |
|||
_is: createKeywordLike("is", { |
|||
startsExpr |
|||
}), |
|||
_mixins: createKeywordLike("mixins", { |
|||
startsExpr |
|||
}), |
|||
_proto: createKeywordLike("proto", { |
|||
startsExpr |
|||
}), |
|||
_require: createKeywordLike("require", { |
|||
startsExpr |
|||
}), |
|||
_satisfies: createKeywordLike("satisfies", { |
|||
startsExpr |
|||
}), |
|||
_keyof: createKeywordLike("keyof", { |
|||
startsExpr |
|||
}), |
|||
_readonly: createKeywordLike("readonly", { |
|||
startsExpr |
|||
}), |
|||
_unique: createKeywordLike("unique", { |
|||
startsExpr |
|||
}), |
|||
_abstract: createKeywordLike("abstract", { |
|||
startsExpr |
|||
}), |
|||
_declare: createKeywordLike("declare", { |
|||
startsExpr |
|||
}), |
|||
_enum: createKeywordLike("enum", { |
|||
startsExpr |
|||
}), |
|||
_module: createKeywordLike("module", { |
|||
startsExpr |
|||
}), |
|||
_namespace: createKeywordLike("namespace", { |
|||
startsExpr |
|||
}), |
|||
_interface: createKeywordLike("interface", { |
|||
startsExpr |
|||
}), |
|||
_type: createKeywordLike("type", { |
|||
startsExpr |
|||
}), |
|||
_opaque: createKeywordLike("opaque", { |
|||
startsExpr |
|||
}), |
|||
name: createToken("name", { |
|||
startsExpr |
|||
}), |
|||
string: createToken("string", { |
|||
startsExpr |
|||
}), |
|||
num: createToken("num", { |
|||
startsExpr |
|||
}), |
|||
bigint: createToken("bigint", { |
|||
startsExpr |
|||
}), |
|||
decimal: createToken("decimal", { |
|||
startsExpr |
|||
}), |
|||
regexp: createToken("regexp", { |
|||
startsExpr |
|||
}), |
|||
privateName: createToken("#name", { |
|||
startsExpr |
|||
}), |
|||
eof: createToken("eof"), |
|||
jsxName: createToken("jsxName"), |
|||
jsxText: createToken("jsxText", { |
|||
beforeExpr: true |
|||
}), |
|||
jsxTagStart: createToken("jsxTagStart", { |
|||
startsExpr: true |
|||
}), |
|||
jsxTagEnd: createToken("jsxTagEnd"), |
|||
placeholder: createToken("%%", { |
|||
startsExpr: true |
|||
}) |
|||
}; |
|||
exports.tt = tt; |
|||
function tokenIsIdentifier(token) { |
|||
return token >= 93 && token <= 130; |
|||
} |
|||
function tokenKeywordOrIdentifierIsKeyword(token) { |
|||
return token <= 92; |
|||
} |
|||
function tokenIsKeywordOrIdentifier(token) { |
|||
return token >= 58 && token <= 130; |
|||
} |
|||
function tokenIsLiteralPropertyName(token) { |
|||
return token >= 58 && token <= 134; |
|||
} |
|||
function tokenComesBeforeExpression(token) { |
|||
return tokenBeforeExprs[token]; |
|||
} |
|||
function tokenCanStartExpression(token) { |
|||
return tokenStartsExprs[token]; |
|||
} |
|||
function tokenIsAssignment(token) { |
|||
return token >= 29 && token <= 33; |
|||
} |
|||
function tokenIsFlowInterfaceOrTypeOrOpaque(token) { |
|||
return token >= 127 && token <= 129; |
|||
} |
|||
function tokenIsLoop(token) { |
|||
return token >= 90 && token <= 92; |
|||
} |
|||
function tokenIsKeyword(token) { |
|||
return token >= 58 && token <= 92; |
|||
} |
|||
function tokenIsOperator(token) { |
|||
return token >= 39 && token <= 59; |
|||
} |
|||
function tokenIsPostfix(token) { |
|||
return token === 34; |
|||
} |
|||
function tokenIsPrefix(token) { |
|||
return tokenPrefixes[token]; |
|||
} |
|||
function tokenIsTSTypeOperator(token) { |
|||
return token >= 119 && token <= 121; |
|||
} |
|||
function tokenIsTSDeclarationStart(token) { |
|||
return token >= 122 && token <= 128; |
|||
} |
|||
function tokenLabelName(token) { |
|||
return tokenLabels[token]; |
|||
} |
|||
function tokenOperatorPrecedence(token) { |
|||
return tokenBinops[token]; |
|||
} |
|||
function tokenIsBinaryOperator(token) { |
|||
return tokenBinops[token] !== -1; |
|||
} |
|||
function tokenIsRightAssociative(token) { |
|||
return token === 57; |
|||
} |
|||
function tokenIsTemplate(token) { |
|||
return token >= 24 && token <= 25; |
|||
} |
|||
function getExportedToken(token) { |
|||
return tokenTypes[token]; |
|||
} |
|||
function isTokenType(obj) { |
|||
return typeof obj === "number"; |
|||
} |
|||
{ |
|||
tokenTypes[8].updateContext = context => { |
|||
context.pop(); |
|||
}; |
|||
tokenTypes[5].updateContext = tokenTypes[7].updateContext = tokenTypes[23].updateContext = context => { |
|||
context.push(_context.types.brace); |
|||
}; |
|||
tokenTypes[22].updateContext = context => { |
|||
if (context[context.length - 1] === _context.types.template) { |
|||
context.pop(); |
|||
} else { |
|||
context.push(_context.types.template); |
|||
} |
|||
}; |
|||
tokenTypes[140].updateContext = context => { |
|||
context.push(_context.types.j_expr, _context.types.j_oTag); |
|||
}; |
|||
} |
|||
|
|||
//# sourceMappingURL=types.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,92 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.ClassScope = void 0; |
|||
var _scopeflags = require("./scopeflags"); |
|||
var _parseError = require("../parse-error"); |
|||
class ClassScope { |
|||
constructor() { |
|||
this.privateNames = new Set(); |
|||
this.loneAccessors = new Map(); |
|||
this.undefinedPrivateNames = new Map(); |
|||
} |
|||
} |
|||
exports.ClassScope = ClassScope; |
|||
class ClassScopeHandler { |
|||
constructor(parser) { |
|||
this.parser = void 0; |
|||
this.stack = []; |
|||
this.undefinedPrivateNames = new Map(); |
|||
this.parser = parser; |
|||
} |
|||
current() { |
|||
return this.stack[this.stack.length - 1]; |
|||
} |
|||
enter() { |
|||
this.stack.push(new ClassScope()); |
|||
} |
|||
exit() { |
|||
const oldClassScope = this.stack.pop(); |
|||
const current = this.current(); |
|||
for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) { |
|||
if (current) { |
|||
if (!current.undefinedPrivateNames.has(name)) { |
|||
current.undefinedPrivateNames.set(name, loc); |
|||
} |
|||
} else { |
|||
this.parser.raise(_parseError.Errors.InvalidPrivateFieldResolution, { |
|||
at: loc, |
|||
identifierName: name |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
declarePrivateName(name, elementType, loc) { |
|||
const { |
|||
privateNames, |
|||
loneAccessors, |
|||
undefinedPrivateNames |
|||
} = this.current(); |
|||
let redefined = privateNames.has(name); |
|||
if (elementType & _scopeflags.CLASS_ELEMENT_KIND_ACCESSOR) { |
|||
const accessor = redefined && loneAccessors.get(name); |
|||
if (accessor) { |
|||
const oldStatic = accessor & _scopeflags.CLASS_ELEMENT_FLAG_STATIC; |
|||
const newStatic = elementType & _scopeflags.CLASS_ELEMENT_FLAG_STATIC; |
|||
const oldKind = accessor & _scopeflags.CLASS_ELEMENT_KIND_ACCESSOR; |
|||
const newKind = elementType & _scopeflags.CLASS_ELEMENT_KIND_ACCESSOR; |
|||
redefined = oldKind === newKind || oldStatic !== newStatic; |
|||
if (!redefined) loneAccessors.delete(name); |
|||
} else if (!redefined) { |
|||
loneAccessors.set(name, elementType); |
|||
} |
|||
} |
|||
if (redefined) { |
|||
this.parser.raise(_parseError.Errors.PrivateNameRedeclaration, { |
|||
at: loc, |
|||
identifierName: name |
|||
}); |
|||
} |
|||
privateNames.add(name); |
|||
undefinedPrivateNames.delete(name); |
|||
} |
|||
usePrivateName(name, loc) { |
|||
let classScope; |
|||
for (classScope of this.stack) { |
|||
if (classScope.privateNames.has(name)) return; |
|||
} |
|||
if (classScope) { |
|||
classScope.undefinedPrivateNames.set(name, loc); |
|||
} else { |
|||
this.parser.raise(_parseError.Errors.InvalidPrivateFieldResolution, { |
|||
at: loc, |
|||
identifierName: name |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
exports.default = ClassScopeHandler; |
|||
|
|||
//# sourceMappingURL=class-scope.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,147 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = void 0; |
|||
exports.newArrowHeadScope = newArrowHeadScope; |
|||
exports.newAsyncArrowScope = newAsyncArrowScope; |
|||
exports.newExpressionScope = newExpressionScope; |
|||
exports.newParameterDeclarationScope = newParameterDeclarationScope; |
|||
var _parseError = require("../parse-error"); |
|||
const kExpression = 0, |
|||
kMaybeArrowParameterDeclaration = 1, |
|||
kMaybeAsyncArrowParameterDeclaration = 2, |
|||
kParameterDeclaration = 3; |
|||
class ExpressionScope { |
|||
constructor(type = kExpression) { |
|||
this.type = void 0; |
|||
this.type = type; |
|||
} |
|||
canBeArrowParameterDeclaration() { |
|||
return this.type === kMaybeAsyncArrowParameterDeclaration || this.type === kMaybeArrowParameterDeclaration; |
|||
} |
|||
isCertainlyParameterDeclaration() { |
|||
return this.type === kParameterDeclaration; |
|||
} |
|||
} |
|||
class ArrowHeadParsingScope extends ExpressionScope { |
|||
constructor(type) { |
|||
super(type); |
|||
this.declarationErrors = new Map(); |
|||
} |
|||
recordDeclarationError(ParsingErrorClass, { |
|||
at |
|||
}) { |
|||
const index = at.index; |
|||
this.declarationErrors.set(index, [ParsingErrorClass, at]); |
|||
} |
|||
clearDeclarationError(index) { |
|||
this.declarationErrors.delete(index); |
|||
} |
|||
iterateErrors(iterator) { |
|||
this.declarationErrors.forEach(iterator); |
|||
} |
|||
} |
|||
class ExpressionScopeHandler { |
|||
constructor(parser) { |
|||
this.parser = void 0; |
|||
this.stack = [new ExpressionScope()]; |
|||
this.parser = parser; |
|||
} |
|||
enter(scope) { |
|||
this.stack.push(scope); |
|||
} |
|||
exit() { |
|||
this.stack.pop(); |
|||
} |
|||
recordParameterInitializerError(toParseError, { |
|||
at: node |
|||
}) { |
|||
const origin = { |
|||
at: node.loc.start |
|||
}; |
|||
const { |
|||
stack |
|||
} = this; |
|||
let i = stack.length - 1; |
|||
let scope = stack[i]; |
|||
while (!scope.isCertainlyParameterDeclaration()) { |
|||
if (scope.canBeArrowParameterDeclaration()) { |
|||
scope.recordDeclarationError(toParseError, origin); |
|||
} else { |
|||
return; |
|||
} |
|||
scope = stack[--i]; |
|||
} |
|||
this.parser.raise(toParseError, origin); |
|||
} |
|||
recordArrowParameterBindingError(error, { |
|||
at: node |
|||
}) { |
|||
const { |
|||
stack |
|||
} = this; |
|||
const scope = stack[stack.length - 1]; |
|||
const origin = { |
|||
at: node.loc.start |
|||
}; |
|||
if (scope.isCertainlyParameterDeclaration()) { |
|||
this.parser.raise(error, origin); |
|||
} else if (scope.canBeArrowParameterDeclaration()) { |
|||
scope.recordDeclarationError(error, origin); |
|||
} else { |
|||
return; |
|||
} |
|||
} |
|||
recordAsyncArrowParametersError({ |
|||
at |
|||
}) { |
|||
const { |
|||
stack |
|||
} = this; |
|||
let i = stack.length - 1; |
|||
let scope = stack[i]; |
|||
while (scope.canBeArrowParameterDeclaration()) { |
|||
if (scope.type === kMaybeAsyncArrowParameterDeclaration) { |
|||
scope.recordDeclarationError(_parseError.Errors.AwaitBindingIdentifier, { |
|||
at |
|||
}); |
|||
} |
|||
scope = stack[--i]; |
|||
} |
|||
} |
|||
validateAsPattern() { |
|||
const { |
|||
stack |
|||
} = this; |
|||
const currentScope = stack[stack.length - 1]; |
|||
if (!currentScope.canBeArrowParameterDeclaration()) return; |
|||
currentScope.iterateErrors(([toParseError, loc]) => { |
|||
this.parser.raise(toParseError, { |
|||
at: loc |
|||
}); |
|||
let i = stack.length - 2; |
|||
let scope = stack[i]; |
|||
while (scope.canBeArrowParameterDeclaration()) { |
|||
scope.clearDeclarationError(loc.index); |
|||
scope = stack[--i]; |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
exports.default = ExpressionScopeHandler; |
|||
function newParameterDeclarationScope() { |
|||
return new ExpressionScope(kParameterDeclaration); |
|||
} |
|||
function newArrowHeadScope() { |
|||
return new ArrowHeadParsingScope(kMaybeArrowParameterDeclaration); |
|||
} |
|||
function newAsyncArrowScope() { |
|||
return new ArrowHeadParsingScope(kMaybeAsyncArrowParameterDeclaration); |
|||
} |
|||
function newExpressionScope() { |
|||
return new ExpressionScope(); |
|||
} |
|||
|
|||
//# sourceMappingURL=expression-scope.js.map
|
|||
File diff suppressed because one or more lines are too long
@ -1,62 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.canBeReservedWord = canBeReservedWord; |
|||
Object.defineProperty(exports, "isIdentifierChar", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isIdentifierChar; |
|||
} |
|||
}); |
|||
Object.defineProperty(exports, "isIdentifierStart", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isIdentifierStart; |
|||
} |
|||
}); |
|||
exports.isIteratorStart = isIteratorStart; |
|||
Object.defineProperty(exports, "isKeyword", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isKeyword; |
|||
} |
|||
}); |
|||
Object.defineProperty(exports, "isReservedWord", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isReservedWord; |
|||
} |
|||
}); |
|||
Object.defineProperty(exports, "isStrictBindOnlyReservedWord", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isStrictBindOnlyReservedWord; |
|||
} |
|||
}); |
|||
Object.defineProperty(exports, "isStrictBindReservedWord", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isStrictBindReservedWord; |
|||
} |
|||
}); |
|||
Object.defineProperty(exports, "isStrictReservedWord", { |
|||
enumerable: true, |
|||
get: function () { |
|||
return _helperValidatorIdentifier.isStrictReservedWord; |
|||
} |
|||
}); |
|||
exports.keywordRelationalOperator = void 0; |
|||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier"); |
|||
const keywordRelationalOperator = /^in(stanceof)?$/; |
|||
exports.keywordRelationalOperator = keywordRelationalOperator; |
|||
function isIteratorStart(current, next, next2) { |
|||
return current === 64 && next === 64 && (0, _helperValidatorIdentifier.isIdentifierStart)(next2); |
|||
} |
|||
const reservedWordLikeSet = new Set(["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield", "eval", "arguments", "enum", "await"]); |
|||
function canBeReservedWord(word) { |
|||
return reservedWordLikeSet.has(word); |
|||
} |
|||
|
|||
//# sourceMappingURL=identifier.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["_helperValidatorIdentifier","require","keywordRelationalOperator","exports","isIteratorStart","current","next","next2","isIdentifierStart","reservedWordLikeSet","Set","canBeReservedWord","word","has"],"sources":["../../src/util/identifier.ts"],"sourcesContent":["/* eslint max-len: 0 */\n\nimport * as charCodes from \"charcodes\";\nimport { isIdentifierStart } from \"@babel/helper-validator-identifier\";\n\nexport {\n isIdentifierStart,\n isIdentifierChar,\n isReservedWord,\n isStrictBindOnlyReservedWord,\n isStrictBindReservedWord,\n isStrictReservedWord,\n isKeyword,\n} from \"@babel/helper-validator-identifier\";\n\nexport const keywordRelationalOperator = /^in(stanceof)?$/;\n\n// Test whether a current state character code and next character code is @\n\nexport function isIteratorStart(\n current: number,\n next: number,\n next2: number,\n): boolean {\n return (\n current === charCodes.atSign &&\n next === charCodes.atSign &&\n isIdentifierStart(next2)\n );\n}\n\n// This is the comprehensive set of JavaScript reserved words\n// If a word is in this set, it could be a reserved word,\n// depending on sourceType/strictMode/binding info. In other words\n// if a word is not in this set, it is not a reserved word under\n// any circumstance.\nconst reservedWordLikeSet = new Set([\n \"break\",\n \"case\",\n \"catch\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"do\",\n \"else\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"return\",\n \"switch\",\n \"throw\",\n \"try\",\n \"var\",\n \"const\",\n \"while\",\n \"with\",\n \"new\",\n \"this\",\n \"super\",\n \"class\",\n \"extends\",\n \"export\",\n \"import\",\n \"null\",\n \"true\",\n \"false\",\n \"in\",\n \"instanceof\",\n \"typeof\",\n \"void\",\n \"delete\",\n // strict\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n \"yield\",\n // strictBind\n \"eval\",\n \"arguments\",\n // reservedWorkLike\n \"enum\",\n \"await\",\n]);\n\nexport function canBeReservedWord(word: string): boolean {\n return reservedWordLikeSet.has(word);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,0BAAA,GAAAC,OAAA;AAYO,MAAMC,yBAAyB,GAAG,iBAAiB;AAACC,OAAA,CAAAD,yBAAA,GAAAA,yBAAA;AAIpD,SAASE,eAAeA,CAC7BC,OAAe,EACfC,IAAY,EACZC,KAAa,EACJ;EACT,OACEF,OAAO,OAAqB,IAC5BC,IAAI,OAAqB,IACzB,IAAAE,4CAAiB,EAACD,KAAK,CAAC;AAE5B;AAOA,MAAME,mBAAmB,GAAG,IAAIC,GAAG,CAAC,CAClC,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,OAAO,EAEP,MAAM,EACN,WAAW,EAEX,MAAM,EACN,OAAO,CACR,CAAC;AAEK,SAASC,iBAAiBA,CAACC,IAAY,EAAW;EACvD,OAAOH,mBAAmB,CAACI,GAAG,CAACD,IAAI,CAAC;AACtC"} |
|||
@ -1,39 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.SourceLocation = exports.Position = void 0; |
|||
exports.createPositionWithColumnOffset = createPositionWithColumnOffset; |
|||
class Position { |
|||
constructor(line, col, index) { |
|||
this.line = void 0; |
|||
this.column = void 0; |
|||
this.index = void 0; |
|||
this.line = line; |
|||
this.column = col; |
|||
this.index = index; |
|||
} |
|||
} |
|||
exports.Position = Position; |
|||
class SourceLocation { |
|||
constructor(start, end) { |
|||
this.start = void 0; |
|||
this.end = void 0; |
|||
this.filename = void 0; |
|||
this.identifierName = void 0; |
|||
this.start = start; |
|||
this.end = end; |
|||
} |
|||
} |
|||
exports.SourceLocation = SourceLocation; |
|||
function createPositionWithColumnOffset(position, columnOffset) { |
|||
const { |
|||
line, |
|||
column, |
|||
index |
|||
} = position; |
|||
return new Position(line, column + columnOffset, index + columnOffset); |
|||
} |
|||
|
|||
//# sourceMappingURL=location.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["Position","constructor","line","col","index","column","exports","SourceLocation","start","end","filename","identifierName","createPositionWithColumnOffset","position","columnOffset"],"sources":["../../src/util/location.ts"],"sourcesContent":["export type Pos = {\n start: number;\n};\n\n// These are used when `options.locations` is on, for the\n// `startLoc` and `endLoc` properties.\n\nexport class Position {\n line: number;\n column: number;\n index: number;\n\n constructor(line: number, col: number, index: number) {\n this.line = line;\n this.column = col;\n this.index = index;\n }\n}\n\nexport class SourceLocation {\n start: Position;\n end: Position;\n filename: string;\n identifierName: string | undefined | null;\n\n constructor(start: Position, end?: Position) {\n this.start = start;\n // (may start as null, but initialized later)\n this.end = end;\n }\n}\n\n/**\n * creates a new position with a non-zero column offset from the given position.\n * This function should be only be used when we create AST node out of the token\n * boundaries, such as TemplateElement ends before tt.templateNonTail. This\n * function does not skip whitespaces.\n */\nexport function createPositionWithColumnOffset(\n position: Position,\n columnOffset: number,\n) {\n const { line, column, index } = position;\n return new Position(line, column + columnOffset, index + columnOffset);\n}\n"],"mappings":";;;;;;;AAOO,MAAMA,QAAQ,CAAC;EAKpBC,WAAWA,CAACC,IAAY,EAAEC,GAAW,EAAEC,KAAa,EAAE;IAAA,KAJtDF,IAAI;IAAA,KACJG,MAAM;IAAA,KACND,KAAK;IAGH,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACG,MAAM,GAAGF,GAAG;IACjB,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;AACF;AAACE,OAAA,CAAAN,QAAA,GAAAA,QAAA;AAEM,MAAMO,cAAc,CAAC;EAM1BN,WAAWA,CAACO,KAAe,EAAEC,GAAc,EAAE;IAAA,KAL7CD,KAAK;IAAA,KACLC,GAAG;IAAA,KACHC,QAAQ;IAAA,KACRC,cAAc;IAGZ,IAAI,CAACH,KAAK,GAAGA,KAAK;IAElB,IAAI,CAACC,GAAG,GAAGA,GAAG;EAChB;AACF;AAACH,OAAA,CAAAC,cAAA,GAAAA,cAAA;AAQM,SAASK,8BAA8BA,CAC5CC,QAAkB,EAClBC,YAAoB,EACpB;EACA,MAAM;IAAEZ,IAAI;IAAEG,MAAM;IAAED;EAAM,CAAC,GAAGS,QAAQ;EACxC,OAAO,IAAIb,QAAQ,CAACE,IAAI,EAAEG,MAAM,GAAGS,YAAY,EAAEV,KAAK,GAAGU,YAAY,CAAC;AACxE"} |
|||
@ -1,49 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.PARAM_YIELD = exports.PARAM_RETURN = exports.PARAM_IN = exports.PARAM_AWAIT = exports.PARAM = void 0; |
|||
exports.functionFlags = functionFlags; |
|||
const PARAM = 0b0000, |
|||
PARAM_YIELD = 0b0001, |
|||
PARAM_AWAIT = 0b0010, |
|||
PARAM_RETURN = 0b0100, |
|||
PARAM_IN = 0b1000; |
|||
exports.PARAM_IN = PARAM_IN; |
|||
exports.PARAM_RETURN = PARAM_RETURN; |
|||
exports.PARAM_AWAIT = PARAM_AWAIT; |
|||
exports.PARAM_YIELD = PARAM_YIELD; |
|||
exports.PARAM = PARAM; |
|||
class ProductionParameterHandler { |
|||
constructor() { |
|||
this.stacks = []; |
|||
} |
|||
enter(flags) { |
|||
this.stacks.push(flags); |
|||
} |
|||
exit() { |
|||
this.stacks.pop(); |
|||
} |
|||
currentFlags() { |
|||
return this.stacks[this.stacks.length - 1]; |
|||
} |
|||
get hasAwait() { |
|||
return (this.currentFlags() & PARAM_AWAIT) > 0; |
|||
} |
|||
get hasYield() { |
|||
return (this.currentFlags() & PARAM_YIELD) > 0; |
|||
} |
|||
get hasReturn() { |
|||
return (this.currentFlags() & PARAM_RETURN) > 0; |
|||
} |
|||
get hasIn() { |
|||
return (this.currentFlags() & PARAM_IN) > 0; |
|||
} |
|||
} |
|||
exports.default = ProductionParameterHandler; |
|||
function functionFlags(isAsync, isGenerator) { |
|||
return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0); |
|||
} |
|||
|
|||
//# sourceMappingURL=production-parameter.js.map
|
|||
@ -1 +0,0 @@ |
|||
{"version":3,"names":["PARAM","PARAM_YIELD","PARAM_AWAIT","PARAM_RETURN","PARAM_IN","exports","ProductionParameterHandler","constructor","stacks","enter","flags","push","exit","pop","currentFlags","length","hasAwait","hasYield","hasReturn","hasIn","default","functionFlags","isAsync","isGenerator"],"sources":["../../src/util/production-parameter.ts"],"sourcesContent":["export const // Initial Parameter flags\n PARAM = 0b0000,\n // track [Yield] production parameter\n PARAM_YIELD = 0b0001,\n // track [Await] production parameter\n PARAM_AWAIT = 0b0010,\n // track [Return] production parameter\n PARAM_RETURN = 0b0100,\n PARAM_IN = 0b1000; // track [In] production parameter\n\n// ProductionParameterHandler is a stack fashioned production parameter tracker\n// https://tc39.es/ecma262/#sec-grammar-notation\n// The tracked parameters are defined above.\n//\n// Whenever [+Await]/[+Yield] appears in the right-hand sides of a production,\n// we must enter a new tracking stack. For example when parsing\n//\n// AsyncFunctionDeclaration [Yield, Await]:\n// async [no LineTerminator here] function BindingIdentifier[?Yield, ?Await]\n// ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody }\n//\n// we must follow such process:\n//\n// 1. parse async keyword\n// 2. parse function keyword\n// 3. parse bindingIdentifier <= inherit current parameters: [?Await]\n// 4. enter new stack with (PARAM_AWAIT)\n// 5. parse formal parameters <= must have [Await] parameter [+Await]\n// 6. parse function body\n// 7. exit current stack\n\nexport type ParamKind = number;\n\n// todo(flow->ts) - check if more granular type can be used,\n// type below is not good because things like PARAM_AWAIT|PARAM_YIELD are not included\n// export type ParamKind =\n// | typeof PARAM\n// | typeof PARAM_AWAIT\n// | typeof PARAM_IN\n// | typeof PARAM_RETURN\n// | typeof PARAM_YIELD;\n\nexport default class ProductionParameterHandler {\n stacks: Array<number> = [];\n enter(flags: number) {\n this.stacks.push(flags);\n }\n\n exit() {\n this.stacks.pop();\n }\n\n currentFlags(): number {\n return this.stacks[this.stacks.length - 1];\n }\n\n get hasAwait(): boolean {\n return (this.currentFlags() & PARAM_AWAIT) > 0;\n }\n\n get hasYield(): boolean {\n return (this.currentFlags() & PARAM_YIELD) > 0;\n }\n\n get hasReturn(): boolean {\n return (this.currentFlags() & PARAM_RETURN) > 0;\n }\n\n get hasIn(): boolean {\n return (this.currentFlags() & PARAM_IN) > 0;\n }\n}\n\nexport function functionFlags(\n isAsync: boolean,\n isGenerator: boolean,\n): ParamKind {\n return (isAsync ? PARAM_AWAIT : 0) | (isGenerator ? PARAM_YIELD : 0);\n}\n"],"mappings":";;;;;;;AAAO,MACLA,KAAK,GAAG,MAAM;EAEdC,WAAW,GAAG,MAAM;EAEpBC,WAAW,GAAG,MAAM;EAEpBC,YAAY,GAAG,MAAM;EACrBC,QAAQ,GAAG,MAAM;AAACC,OAAA,CAAAD,QAAA,GAAAA,QAAA;AAAAC,OAAA,CAAAF,YAAA,GAAAA,YAAA;AAAAE,OAAA,CAAAH,WAAA,GAAAA,WAAA;AAAAG,OAAA,CAAAJ,WAAA,GAAAA,WAAA;AAAAI,OAAA,CAAAL,KAAA,GAAAA,KAAA;AAkCL,MAAMM,0BAA0B,CAAC;EAAAC,YAAA;IAAA,KAC9CC,MAAM,GAAkB,EAAE;EAAA;EAC1BC,KAAKA,CAACC,KAAa,EAAE;IACnB,IAAI,CAACF,MAAM,CAACG,IAAI,CAACD,KAAK,CAAC;EACzB;EAEAE,IAAIA,CAAA,EAAG;IACL,IAAI,CAACJ,MAAM,CAACK,GAAG,EAAE;EACnB;EAEAC,YAAYA,CAAA,EAAW;IACrB,OAAO,IAAI,CAACN,MAAM,CAAC,IAAI,CAACA,MAAM,CAACO,MAAM,GAAG,CAAC,CAAC;EAC5C;EAEA,IAAIC,QAAQA,CAAA,EAAY;IACtB,OAAO,CAAC,IAAI,CAACF,YAAY,EAAE,GAAGZ,WAAW,IAAI,CAAC;EAChD;EAEA,IAAIe,QAAQA,CAAA,EAAY;IACtB,OAAO,CAAC,IAAI,CAACH,YAAY,EAAE,GAAGb,WAAW,IAAI,CAAC;EAChD;EAEA,IAAIiB,SAASA,CAAA,EAAY;IACvB,OAAO,CAAC,IAAI,CAACJ,YAAY,EAAE,GAAGX,YAAY,IAAI,CAAC;EACjD;EAEA,IAAIgB,KAAKA,CAAA,EAAY;IACnB,OAAO,CAAC,IAAI,CAACL,YAAY,EAAE,GAAGV,QAAQ,IAAI,CAAC;EAC7C;AACF;AAACC,OAAA,CAAAe,OAAA,GAAAd,0BAAA;AAEM,SAASe,aAAaA,CAC3BC,OAAgB,EAChBC,WAAoB,EACT;EACX,OAAO,CAACD,OAAO,GAAGpB,WAAW,GAAG,CAAC,KAAKqB,WAAW,GAAGtB,WAAW,GAAG,CAAC,CAAC;AACtE"} |
|||
@ -1,161 +0,0 @@ |
|||
"use strict"; |
|||
|
|||
Object.defineProperty(exports, "__esModule", { |
|||
value: true |
|||
}); |
|||
exports.default = exports.Scope = void 0; |
|||
var _scopeflags = require("./scopeflags"); |
|||
var _parseError = require("../parse-error"); |
|||
class Scope { |
|||
constructor(flags) { |
|||
this.var = new Set(); |
|||
this.lexical = new Set(); |
|||
this.functions = new Set(); |
|||
this.flags = flags; |
|||
} |
|||
} |
|||
exports.Scope = Scope; |
|||
class ScopeHandler { |
|||
constructor(parser, inModule) { |
|||
this.parser = void 0; |
|||
this.scopeStack = []; |
|||
this.inModule = void 0; |
|||
this.undefinedExports = new Map(); |
|||
this.parser = parser; |
|||
this.inModule = inModule; |
|||
} |
|||
get inTopLevel() { |
|||
return (this.currentScope().flags & _scopeflags.SCOPE_PROGRAM) > 0; |
|||
} |
|||
get inFunction() { |
|||
return (this.currentVarScopeFlags() & _scopeflags.SCOPE_FUNCTION) > 0; |
|||
} |
|||
get allowSuper() { |
|||
return (this.currentThisScopeFlags() & _scopeflags.SCOPE_SUPER) > 0; |
|||
} |
|||
get allowDirectSuper() { |
|||
return (this.currentThisScopeFlags() & _scopeflags.SCOPE_DIRECT_SUPER) > 0; |
|||
} |
|||
get inClass() { |
|||
return (this.currentThisScopeFlags() & _scopeflags.SCOPE_CLASS) > 0; |
|||
} |
|||
get inClassAndNotInNonArrowFunction() { |
|||
const flags = this.currentThisScopeFlags(); |
|||
return (flags & _scopeflags.SCOPE_CLASS) > 0 && (flags & _scopeflags.SCOPE_FUNCTION) === 0; |
|||
} |
|||
get inStaticBlock() { |
|||
for (let i = this.scopeStack.length - 1;; i--) { |
|||
const { |
|||
flags |
|||
} = this.scopeStack[i]; |
|||
if (flags & _scopeflags.SCOPE_STATIC_BLOCK) { |
|||
return true; |
|||
} |
|||
if (flags & (_scopeflags.SCOPE_VAR | _scopeflags.SCOPE_CLASS)) { |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
get inNonArrowFunction() { |
|||
return (this.currentThisScopeFlags() & _scopeflags.SCOPE_FUNCTION) > 0; |
|||
} |
|||
get treatFunctionsAsVar() { |
|||
return this.treatFunctionsAsVarInScope(this.currentScope()); |
|||
} |
|||
createScope(flags) { |
|||
return new Scope(flags); |
|||
} |
|||
enter(flags) { |
|||
this.scopeStack.push(this.createScope(flags)); |
|||
} |
|||
exit() { |
|||
const scope = this.scopeStack.pop(); |
|||
return scope.flags; |
|||
} |
|||
treatFunctionsAsVarInScope(scope) { |
|||
return !!(scope.flags & (_scopeflags.SCOPE_FUNCTION | _scopeflags.SCOPE_STATIC_BLOCK) || !this.parser.inModule && scope.flags & _scopeflags.SCOPE_PROGRAM); |
|||
} |
|||
declareName(name, bindingType, loc) { |
|||
let scope = this.currentScope(); |
|||
if (bindingType & _scopeflags.BIND_SCOPE_LEXICAL || bindingType & _scopeflags.BIND_SCOPE_FUNCTION) { |
|||
this.checkRedeclarationInScope(scope, name, bindingType, loc); |
|||
if (bindingType & _scopeflags.BIND_SCOPE_FUNCTION) { |
|||
scope.functions.add(name); |
|||
} else { |
|||
scope.lexical.add(name); |
|||
} |
|||
if (bindingType & _scopeflags.BIND_SCOPE_LEXICAL) { |
|||
this.maybeExportDefined(scope, name); |
|||
} |
|||
} else if (bindingType & _scopeflags.BIND_SCOPE_VAR) { |
|||
for (let i = this.scopeStack.length - 1; i >= 0; --i) { |
|||
scope = this.scopeStack[i]; |
|||
this.checkRedeclarationInScope(scope, name, bindingType, loc); |
|||
scope.var.add(name); |
|||
this.maybeExportDefined(scope, name); |
|||
if (scope.flags & _scopeflags.SCOPE_VAR) break; |
|||
} |
|||
} |
|||
if (this.parser.inModule && scope.flags & _scopeflags.SCOPE_PROGRAM) { |
|||
this.undefinedExports.delete(name); |
|||
} |
|||
} |
|||
maybeExportDefined(scope, name) { |
|||
if (this.parser.inModule && scope.flags & _scopeflags.SCOPE_PROGRAM) { |
|||
this.undefinedExports.delete(name); |
|||
} |
|||
} |
|||
checkRedeclarationInScope(scope, name, bindingType, loc) { |
|||
if (this.isRedeclaredInScope(scope, name, bindingType)) { |
|||
this.parser.raise(_parseError.Errors.VarRedeclaration, { |
|||
at: loc, |
|||
identifierName: name |
|||
}); |
|||
} |
|||
} |
|||
isRedeclaredInScope(scope, name, bindingType) { |
|||
if (!(bindingType & _scopeflags.BIND_KIND_VALUE)) return false; |
|||
if (bindingType & _scopeflags.BIND_SCOPE_LEXICAL) { |
|||
return scope.lexical.has(name) || scope.functions.has(name) || scope.var.has(name); |
|||
} |
|||
if (bindingType & _scopeflags.BIND_SCOPE_FUNCTION) { |
|||
return scope.lexical.has(name) || !this.treatFunctionsAsVarInScope(scope) && scope.var.has(name); |
|||
} |
|||
return scope.lexical.has(name) && !(scope.flags & _scopeflags.SCOPE_SIMPLE_CATCH && scope.lexical.values().next().value === name) || !this.treatFunctionsAsVarInScope(scope) && scope.functions.has(name); |
|||
} |
|||
checkLocalExport(id) { |
|||
const { |
|||
name |
|||
} = id; |
|||
const topLevelScope = this.scopeStack[0]; |
|||
if (!topLevelScope.lexical.has(name) && !topLevelScope.var.has(name) && !topLevelScope.functions.has(name)) { |
|||
this.undefinedExports.set(name, id.loc.start); |
|||
} |
|||
} |
|||
currentScope() { |
|||
return this.scopeStack[this.scopeStack.length - 1]; |
|||
} |
|||
currentVarScopeFlags() { |
|||
for (let i = this.scopeStack.length - 1;; i--) { |
|||
const { |
|||
flags |
|||
} = this.scopeStack[i]; |
|||
if (flags & _scopeflags.SCOPE_VAR) { |
|||
return flags; |
|||
} |
|||
} |
|||
} |
|||
currentThisScopeFlags() { |
|||
for (let i = this.scopeStack.length - 1;; i--) { |
|||
const { |
|||
flags |
|||
} = this.scopeStack[i]; |
|||
if (flags & (_scopeflags.SCOPE_VAR | _scopeflags.SCOPE_CLASS) && !(flags & _scopeflags.SCOPE_ARROW)) { |
|||
return flags; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
exports.default = ScopeHandler; |
|||
|
|||
//# sourceMappingURL=scope.js.map
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue