Initial commit
commit
83ccc6370c
|
@ -0,0 +1,87 @@
|
|||
|
||||
// Credit to http://m1el.github.io/smallest-lambda-eval/
|
||||
function Eval(prog, env) {
|
||||
if (typeof prog === 'string') {
|
||||
// lookup a variable
|
||||
return env[prog];
|
||||
} else if (prog[0] === '$') {
|
||||
// constructing a new lambda
|
||||
return (arg) => Eval(prog[2], { ...env, [prog[1]]: arg });
|
||||
} else {
|
||||
// function application
|
||||
return Eval(prog[0], env)(Eval(prog[1], env));
|
||||
}
|
||||
}
|
||||
function FromChurch(f) {
|
||||
var i = 0;
|
||||
f(function (x) {
|
||||
i++;
|
||||
return x;
|
||||
})(function (x) {
|
||||
return x;
|
||||
})(undefined);
|
||||
}
|
||||
function ToChurch(i) {
|
||||
return function (a) {
|
||||
return function (b) {
|
||||
var c = b;
|
||||
for (let j = 0; j < i; j++)c = a(c);
|
||||
return c
|
||||
}
|
||||
}
|
||||
}
|
||||
function FromArray(x) {
|
||||
return x([])((a) => (v) => [...a, v])
|
||||
}
|
||||
function ToArray(x) {
|
||||
return function (n) {
|
||||
return function (s) {
|
||||
var o = n;
|
||||
for (var i of x) {
|
||||
o = s(o)(i);
|
||||
}
|
||||
return o
|
||||
}
|
||||
}
|
||||
}
|
||||
function FromString(x) {
|
||||
return String.fromCodePoint(...FromArray(x).map(FromChurch))
|
||||
}
|
||||
function ToString(s){
|
||||
return toArray([...s].map(x => x.codePointAt(0)).map(FromChurch))
|
||||
}
|
||||
var opcodes = {
|
||||
0: 'io_ref_new',
|
||||
1: 'io_ref_read',
|
||||
2: 'io_ref_write',
|
||||
}
|
||||
function RunIO(prog) {
|
||||
return prog(function(x){
|
||||
return x;
|
||||
})(function (ty) {
|
||||
return function (pay) {
|
||||
return function (cont) {
|
||||
var then = function(x){
|
||||
return RunIO(cont(x))
|
||||
}
|
||||
switch (opcodes[FromChurch(ty)]) {
|
||||
case 'io_ref_new':
|
||||
var x = Math.random().toString();
|
||||
RunIO["io_ref/" + x] = pay;
|
||||
return then(ToString(x));
|
||||
case 'io_ref_read':
|
||||
return then(RunIO["io_ref/" + FromString(pay)])
|
||||
case 'io_ref_write':
|
||||
return pay(function(a){
|
||||
return function(b){
|
||||
RunIO["io_ref/" + FromString(a)] = b;
|
||||
return then(b);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
RunIO(Eval([["$","val",["$","p",["$","i",["p","val"]]]],["$","+",["$","0","0"]]],{}))
|
||||
|
|
@ -0,0 +1,286 @@
|
|||
let {reduceUsing} = require('shift-reducer')
|
||||
|
||||
const cyrb53 = (str, seed = 0) => {
|
||||
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
||||
for(let i = 0, ch; i < str.length; i++) {
|
||||
ch = str.charCodeAt(i);
|
||||
h1 = Math.imul(h1 ^ ch, 2654435761);
|
||||
h2 = Math.imul(h2 ^ ch, 1597334677);
|
||||
}
|
||||
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
||||
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
||||
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
||||
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
||||
|
||||
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
||||
};
|
||||
|
||||
let srcBase = `
|
||||
// Credit to http://m1el.github.io/smallest-lambda-eval/
|
||||
function Eval(prog, env) {
|
||||
if (typeof prog === 'string') {
|
||||
// lookup a variable
|
||||
return env[prog];
|
||||
} else if (prog[0] === '$') {
|
||||
// constructing a new lambda
|
||||
return (arg) => Eval(prog[2], { ...env, [prog[1]]: arg });
|
||||
} else {
|
||||
// function application
|
||||
return Eval(prog[0], env)(Eval(prog[1], env));
|
||||
}
|
||||
}
|
||||
function FromChurch(f) {
|
||||
var i = 0;
|
||||
f(function (x) {
|
||||
i++;
|
||||
return x;
|
||||
})(function (x) {
|
||||
return x;
|
||||
})(undefined);
|
||||
}
|
||||
function ToChurch(i) {
|
||||
return function (a) {
|
||||
return function (b) {
|
||||
var c = b;
|
||||
for (let j = 0; j < i; j++)c = a(c);
|
||||
return c
|
||||
}
|
||||
}
|
||||
}
|
||||
function FromArray(x) {
|
||||
return x([])((a) => (v) => [...a, v])
|
||||
}
|
||||
function ToArray(x) {
|
||||
return function (n) {
|
||||
return function (s) {
|
||||
var o = n;
|
||||
for (var i of x) {
|
||||
o = s(o)(i);
|
||||
}
|
||||
return o
|
||||
}
|
||||
}
|
||||
}
|
||||
function FromString(x) {
|
||||
return String.fromCodePoint(...FromArray(x).map(FromChurch))
|
||||
}
|
||||
function ToString(s){
|
||||
return toArray([...s].map(x => x.codePointAt(0)).map(FromChurch))
|
||||
}
|
||||
var opcodes = {
|
||||
0: 'io_ref_new',
|
||||
1: 'io_ref_read',
|
||||
2: 'io_ref_write',
|
||||
}
|
||||
function RunIO(prog) {
|
||||
return prog(function(x){
|
||||
return x;
|
||||
})(function (ty) {
|
||||
return function (pay) {
|
||||
return function (cont) {
|
||||
var then = function(x){
|
||||
return RunIO(cont(x))
|
||||
}
|
||||
switch (opcodes[FromChurch(ty)]) {
|
||||
case 'io_ref_new':
|
||||
var x = Math.random().toString();
|
||||
RunIO["io_ref/" + x] = pay;
|
||||
return then(ToString(x));
|
||||
case 'io_ref_read':
|
||||
return then(RunIO["io_ref/" + FromString(pay)])
|
||||
case 'io_ref_write':
|
||||
return pay(function(a){
|
||||
return function(b){
|
||||
RunIO["io_ref/" + FromString(a)] = b;
|
||||
return then(b);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}`
|
||||
|
||||
function vari(x){
|
||||
return x;
|
||||
}
|
||||
|
||||
function abs(a,b){
|
||||
return ['$',a,b]
|
||||
}
|
||||
|
||||
function app(a,b){
|
||||
return [a,b]
|
||||
}
|
||||
|
||||
function appx(...a){
|
||||
var b = a[0];
|
||||
for(var i in a){
|
||||
if(i != 0){
|
||||
b = app(b,a[i])
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
function subst(x,b,c){
|
||||
if(typeof x == 'string'){
|
||||
if(x === b)return c;
|
||||
return x;
|
||||
}else if (x[0] == '$'){
|
||||
if(x[1] == b){
|
||||
return x;
|
||||
}
|
||||
return abs(x[1],subst(x[2],b,c));
|
||||
}
|
||||
return app(subst(x[0],b,c),subst(x[1],b,c))
|
||||
}
|
||||
|
||||
Function.prototype.fuse = function(){
|
||||
var a = abs('$$0',this('$$0'))
|
||||
var h = cyrb53(JSON.stringify(a))
|
||||
return abs(`h${h}`,subst(a[2],'$$0',`h${h}`))
|
||||
}
|
||||
|
||||
function createChurch(n){
|
||||
var v = '0';
|
||||
for(let i = 0; i < n; i++){
|
||||
v = ['+',v];
|
||||
}
|
||||
return ['$','+',['$','0',v]]
|
||||
}
|
||||
function createList(n){
|
||||
var v = 'null';
|
||||
for(var i of n){
|
||||
v = app('push')(v)(i);
|
||||
}
|
||||
return abs('null',abs('push',v))
|
||||
}
|
||||
function createString(s){
|
||||
return createList([...s].map(x => x.codePointAt(0)).map(createChurch))
|
||||
}
|
||||
function createBool(b){
|
||||
return abs('x',app('y',b ? 'x' : 'y'))
|
||||
}
|
||||
var yb = abs('f',abs('x',app('x',abs('z',app(app(app('f','f'),'x'),'z')))))
|
||||
var y = app(yb,yb)
|
||||
var IO = {
|
||||
pure: abs('val',abs('p',abs('i',app('p','val')))),
|
||||
bind: app(y,abs('bind',abs('m',abs('f',app(app('m','f'),abs('ty',abs('pay',abs('cont',abs('h',app(app(app('h','ty'),'pay'),abs('x',app(app('bind',app('cont','x')),'f')))))))))))),
|
||||
name: 'io'
|
||||
}
|
||||
var createIO = abs('t',abs('p',abs('pu',abs('i',appx('i','t','p',IO.pure)))))
|
||||
var newIORef = appx(createIO,createChurch(0))
|
||||
var readIORef = appx(createIO,createChurch(1))
|
||||
var writeIORef = abs('r',abs('v',appx(createIO,createChurch(2),abs('f',appx('f','r','v')))))
|
||||
|
||||
function warp(x,{pure,bind,name} = IO){
|
||||
if(typeof x == 'string'){
|
||||
return app(pure,name + '$' + x);
|
||||
}else if (x[0] == '$'){
|
||||
return app(pure,abs(name + '$' + x[1],warpIO(x[2])))
|
||||
}else if(x[0] == 'splice_' + name){
|
||||
return x[1];
|
||||
}
|
||||
return appx(bind,warp(x[0],{pure,bind,name}),abs('f',appx(bind,warp(x[1],{pure,bind,name}),abs('x',app('f','x')))))
|
||||
}
|
||||
|
||||
|
||||
var pred = abs('n',abs('f',abs('x',app(app(app('n',abs('g',abs('h',app('h',app('g','f'))))),abs('u','x')),abs('u','u')))))
|
||||
var isZero = abs('n',app(app('n',abs('x',createBool(false)),createBool(true))))
|
||||
var l_and = abs('p',abs('q',app(app('p','q'),'p')))
|
||||
var minus = abs('a',abs('b',app(app('b',pred),'a')))
|
||||
var leq = abs('m',abs('n',app(isZero,app(app(minus,'m'),'n'))))
|
||||
var eq = abs('m',abs('n',app(app(l_and,app(app(leq,'m'),'n')),app(app(leq,'n'),'m'))))
|
||||
|
||||
var tru = abs('t',abs('f','t'))
|
||||
var fals = abs('t',abs('f','f'))
|
||||
|
||||
var jsFun = abs('x',abs('fn',abs('truthy',abs('falsy',app('fn','x')))))
|
||||
var jsTruthy = abs('t',abs('v',abs('fn',abs('truthy',abs('falsy',app(app('truthy','t'),'v'))))))
|
||||
var jsFalsy = abs('t',app('fn',abs('truthy',abs('falsy',app('falsy','t')))))
|
||||
|
||||
var sempty = abs('e',abs('c','e'))
|
||||
var scons = abs('h',abs('t',abs('e',abs('c',appx('c','h','t')))))
|
||||
|
||||
var stoc = appx(y,function(a){
|
||||
return abs('l',abs('n',abs('c',appx('l','n',abs('a',abs('b',appx('c','a',appx(a,'b','n','c'))))))))
|
||||
}.fuse)
|
||||
|
||||
var ctos = abs('a',appx('a',sempty,scons))
|
||||
|
||||
var strEq = appx(y,abs('strEq',abs('a',abs('b',appx('a',appx('b',tru,abs('_a',abs('_b',fals))),abs('c',abs('d',appx('b',fals,abs('e',abs('f',appx(eq,'c','e',appx('strEq','d','f'),fals)))))))))))
|
||||
|
||||
var churchSucc = abs('x',abs('o',abs('s',app('s',appx('x','o','s')))))
|
||||
|
||||
var TY_NULL = 0;
|
||||
|
||||
var jsNull = app(jsFalsy,createChurch(TY_NULL))
|
||||
|
||||
var getVarS = getGetVarSlot => abs('v',abs('p',abs('b',abs('l',appx(stoc,'l',abs('_',appx(free.pure,jsNull)),abs('f',abs('p',appx(getGetVarSlot('f'),'p'))),'v')))))
|
||||
|
||||
var free = {
|
||||
name: 'free',
|
||||
pure: abs('x',abs('p',abs('b',abs('l',app('p','x'))))),
|
||||
bind: abs('m',abs('f',abs('p',abs('b',abs('l',appx('b',appx('m','p','b','l'),abs('v',appx('f','v','p','b','l'))))))))
|
||||
}
|
||||
|
||||
var addVarS = push => abs('f',abs('v',abs('p',abs('b',abs('l',appx('f',
|
||||
abs('v',abs('x',app('p','v'))), // pure
|
||||
abs('m',abs('f',abs('x',appx('b',app('m','x'),abs('v',appx('f','v','x')))))), // bind
|
||||
appx(scons,push(
|
||||
abs('m',abs('x','m')), //lift
|
||||
abs('r',abs('v',abs('x',appx(isZero,'v',app(free.pure,'x'),abs('_', appx('r',appx(pred,'v'))))))), //getVar
|
||||
),'l'),
|
||||
'v'
|
||||
))))))
|
||||
|
||||
var liftIOS = getLift => abs('i',abs('p',abs('b',app('l',appx(stoc,'l','i',abs('d',abs('m',app(getLift('d'),'m'))))))))
|
||||
|
||||
|
||||
var readerT = old => ({
|
||||
base: old,
|
||||
lift: abs('x',abs('v','x')),
|
||||
pure: abs('x',abs('v',app(old.pure,'x'))),
|
||||
bind: abs('m',abs('f',abs('v',appx(old.bind,app('m','v'),abs('w',appx('f','w','v')))))),
|
||||
name: `readerT(${old.name})`
|
||||
})
|
||||
|
||||
var contT = old => ({
|
||||
base: old,
|
||||
lift: abs('x',abs('cc',appx(old.bind,'x','cc'))),
|
||||
pure: abs('x',abs('cc',app('cc','x'))),
|
||||
bind: abs('m',abs('f',abs('cc',app('m',abs('x',appx('f','x','cc')))))),
|
||||
name: `contT(${old.name})`
|
||||
})
|
||||
|
||||
var js = contT(readerT(free))
|
||||
|
||||
var getVarB = getGetVarSlot => abs('j',app(js.lift,abs('vs',appx(getVarS(getGetVarSlot),appx('vs','j')))))
|
||||
|
||||
var liftIOB = getLift => abs('i',app(js.lift,abs('v',appx(liftIOS(getLift),'i'))))
|
||||
|
||||
var pushBase = (a,b) => abs('f',appx('f',a,b))
|
||||
|
||||
var addVarB = push => abs('m',abs('v',abs('f',appx(js.base.lift,addVarS(push),appx('f',abs('n',appx(strEq,'m','n',createChurch(0),app(churchSucc,app('f','n'))))),'v'))));
|
||||
|
||||
var addVar = addVarB(pushBase)
|
||||
|
||||
js.addVar = addVar
|
||||
|
||||
var getGetVarSlotBase = x => app(x,abs('a',abs('b','b')))
|
||||
|
||||
var getLiftBase = x => app(x,abs('a',abs('b','a')))
|
||||
|
||||
var getVar = getVarB(getGetVarSlotBase)
|
||||
|
||||
js.getVar = getVar
|
||||
|
||||
var liftIOJ = liftIOB(getLiftBase)
|
||||
|
||||
js.liftIO = liftIOJ
|
||||
|
||||
|
||||
console.log(srcBase + `
|
||||
RunIO(Eval(${JSON.stringify(app(IO.pure,createChurch(0)))},{}))
|
||||
`)
|
|
@ -0,0 +1,83 @@
|
|||
{
|
||||
"name": "lambdaworld",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/multimap": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz",
|
||||
"integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw=="
|
||||
},
|
||||
"node_modules/shift-ast": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-7.0.0.tgz",
|
||||
"integrity": "sha512-O0INwsZa1XH/lMSf52udGnjNOxKBLxFiZHt0Ys3i6bqtwuGEA3eDR4+e0qJELIsCy8+BiTtlTgQzP76K1ehipQ=="
|
||||
},
|
||||
"node_modules/shift-parser": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-parser/-/shift-parser-8.0.0.tgz",
|
||||
"integrity": "sha512-IShW1wGhvA5e+SPNVQ+Dwi/Be6651F2jZc6wwYHbYW7PiswAYfvR/v3Q+CjjxsVCna5L6J5OtR6y+tkkCzvCfw==",
|
||||
"dependencies": {
|
||||
"multimap": "^1.0.2",
|
||||
"shift-ast": "7.0.0",
|
||||
"shift-reducer": "7.0.0",
|
||||
"shift-regexp-acceptor": "3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shift-reducer": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-7.0.0.tgz",
|
||||
"integrity": "sha512-9igIDMHzp1+CkQZITGHM1sAd9jqMPV0vhqHuh8jlYumHSMIwsYcrDeo1tlpzNRUnfbEq1nLyh8Bf1YU8HGUE7g==",
|
||||
"dependencies": {
|
||||
"shift-ast": "7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shift-regexp-acceptor": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-regexp-acceptor/-/shift-regexp-acceptor-3.0.0.tgz",
|
||||
"integrity": "sha512-98UKizBjHY6SjjLUr51YYw4rtR+vxjGFm8znqNsoahesAI8Y9+WVAyiBCxxkov1KSDhW0Wz8FwwUqHnlFnjdUg==",
|
||||
"dependencies": {
|
||||
"unicode-match-property-ecmascript": "1.0.4",
|
||||
"unicode-match-property-value-ecmascript": "1.0.2",
|
||||
"unicode-property-aliases-ecmascript": "1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-canonical-property-names-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-match-property-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==",
|
||||
"dependencies": {
|
||||
"unicode-canonical-property-names-ecmascript": "^1.0.4",
|
||||
"unicode-property-aliases-ecmascript": "^1.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-match-property-value-ecmascript": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz",
|
||||
"integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-property-aliases-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"passfail" : false,
|
||||
"maxerr" : 20,
|
||||
"browser" : false,
|
||||
"node" : true,
|
||||
"debug" : false,
|
||||
"devel" : true,
|
||||
"es5" : false,
|
||||
"strict" : false,
|
||||
"globalstrict" : false,
|
||||
"asi" : false,
|
||||
"laxbreak" : false,
|
||||
"bitwise" : false,
|
||||
"boss" : true,
|
||||
"curly" : false,
|
||||
"eqeqeq" : false,
|
||||
"eqnull" : false,
|
||||
"evil" : true,
|
||||
"expr" : true,
|
||||
"forin" : false,
|
||||
"immed" : true,
|
||||
"latedef" : false,
|
||||
"loopfunc" : true,
|
||||
"noarg" : true,
|
||||
"regexp" : true,
|
||||
"regexdash" : false,
|
||||
"scripturl" : true,
|
||||
"shadow" : true,
|
||||
"supernew" : false,
|
||||
"undef" : false,
|
||||
"newcap" : false,
|
||||
"proto" : true,
|
||||
"noempty" : true,
|
||||
"nonew" : false,
|
||||
"nomen" : false,
|
||||
"onevar" : false,
|
||||
"plusplus" : false,
|
||||
"sub" : false,
|
||||
"trailing" : false,
|
||||
"white" : false
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
|
||||
script: npm run test
|
|
@ -0,0 +1,136 @@
|
|||
# Multimap - Map which Allow Multiple Values for the same Key
|
||||
|
||||
[![NPM version](https://badge.fury.io/js/multimap.svg)](http://badge.fury.io/js/multimap)
|
||||
[![Build Status](https://travis-ci.org/villadora/multi-map.png?branch=master)](https://travis-ci.org/villadora/multi-map)
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install multimap --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `Map` on global scope, do:
|
||||
|
||||
```javascript
|
||||
var Multimap = require('multimap');
|
||||
var m = new Multimap();
|
||||
```
|
||||
|
||||
If the global es6 `Map` exists or `Multimap.Map` is set, `Multimap` will use the `Map` as inner store, that means Object can be used as key.
|
||||
|
||||
```javascript
|
||||
var Multimap = require('multimap');
|
||||
|
||||
// if harmony is on
|
||||
/* nothing need to do */
|
||||
// or if you are using es6-shim
|
||||
Multimap.Map = ShimMap;
|
||||
|
||||
var m = new Multimap();
|
||||
var key = {};
|
||||
m.set(key, 'one');
|
||||
|
||||
```
|
||||
|
||||
Otherwise, an object will be used, all the keys will be transformed into string.
|
||||
|
||||
|
||||
### In Modern Browser
|
||||
|
||||
Just download the `index.js` as `Multimap.js`.
|
||||
|
||||
```
|
||||
<script src=Multimap.js"></script>
|
||||
<script>
|
||||
var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
|
||||
map = map.set('b', 20);
|
||||
map.get('b'); // [2, 20]
|
||||
</script>
|
||||
```
|
||||
|
||||
Or use as an AMD loader:
|
||||
|
||||
```
|
||||
require(['./Multimap.js'], function (Multimap) {
|
||||
var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
|
||||
map = map.set('b', 20);
|
||||
map.get('b'); // [2, 20]
|
||||
});
|
||||
```
|
||||
|
||||
* Browsers should support `Object.defineProperty` and `Array.prototype.forEach`.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
Following shows how to use `Multimap`:
|
||||
|
||||
```javascript
|
||||
var Multimap = require('multimap');
|
||||
|
||||
var map = new Multimap([['a', 'one'], ['b', 1], ['a', 'two'], ['b', 2]]);
|
||||
|
||||
map.size; // 4
|
||||
map.count; // 2
|
||||
|
||||
map.get('a'); // ['one', 'two']
|
||||
map.get('b'); // [1, 2]
|
||||
|
||||
map.has('a'); // true
|
||||
map.has('foo'); // false
|
||||
|
||||
map.has('a', 'one'); // true
|
||||
map.has('b', 3); // false
|
||||
|
||||
map.set('a', 'three');
|
||||
map.size; // 5
|
||||
map.count; // 2
|
||||
map.get('a'); // ['one', 'two', 'three']
|
||||
|
||||
map.set('b', 3, 4);
|
||||
map.size; // 7
|
||||
map.count; // 2
|
||||
|
||||
map.delete('a', 'three'); // true
|
||||
map.delete('x'); // false
|
||||
map.delete('a', 'four'); // false
|
||||
map.delete('b'); // true
|
||||
|
||||
map.size; // 2
|
||||
map.count; // 1
|
||||
|
||||
map.set('b', 1, 2);
|
||||
map.size; // 4
|
||||
map.count; // 2
|
||||
|
||||
|
||||
map.forEach(function (value, key) {
|
||||
// iterates { 'one', 'a' }, { 'two', 'a' }, { 1, b }, { 2, 'b' }
|
||||
});
|
||||
|
||||
map.forEachEntry(function (entry, key) {
|
||||
// iterates {['one', 'two'], 'a' }, {[1, 2], 'b' }
|
||||
});
|
||||
|
||||
|
||||
var keys = map.keys(); // iterator with ['a', 'b']
|
||||
keys.next().value; // 'a'
|
||||
var values = map.values(); // iterator ['one', 'two', 1, 2]
|
||||
|
||||
map.clear(); // undefined
|
||||
map.size; // 0
|
||||
map.count; // 0
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013, Villa.Gao <jky239@gmail.com>;
|
||||
All rights reserved.
|
|
@ -0,0 +1,226 @@
|
|||
"use strict";
|
||||
|
||||
/* global module, define */
|
||||
|
||||
function mapEach(map, operation){
|
||||
var keys = map.keys();
|
||||
var next;
|
||||
while(!(next = keys.next()).done) {
|
||||
operation(map.get(next.value), next.value, map);
|
||||
}
|
||||
}
|
||||
|
||||
var Multimap = (function() {
|
||||
var mapCtor;
|
||||
if (typeof Map !== 'undefined') {
|
||||
mapCtor = Map;
|
||||
|
||||
if (!Map.prototype.keys) {
|
||||
Map.prototype.keys = function() {
|
||||
var keys = [];
|
||||
this.forEach(function(item, key) {
|
||||
keys.push(key);
|
||||
});
|
||||
return keys;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function Multimap(iterable) {
|
||||
var self = this;
|
||||
|
||||
self._map = mapCtor;
|
||||
|
||||
if (Multimap.Map) {
|
||||
self._map = Multimap.Map;
|
||||
}
|
||||
|
||||
self._ = self._map ? new self._map() : {};
|
||||
|
||||
if (iterable) {
|
||||
iterable.forEach(function(i) {
|
||||
self.set(i[0], i[1]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} key
|
||||
* @return {Array} An array of values, undefined if no such a key;
|
||||
*/
|
||||
Multimap.prototype.get = function(key) {
|
||||
return this._map ? this._.get(key) : this._[key];
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} key
|
||||
* @param {Object} val...
|
||||
*/
|
||||
Multimap.prototype.set = function(key, val) {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
|
||||
key = args.shift();
|
||||
|
||||
var entry = this.get(key);
|
||||
if (!entry) {
|
||||
entry = [];
|
||||
if (this._map)
|
||||
this._.set(key, entry);
|
||||
else
|
||||
this._[key] = entry;
|
||||
}
|
||||
|
||||
Array.prototype.push.apply(entry, args);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} key
|
||||
* @param {Object=} val
|
||||
* @return {boolean} true if any thing changed
|
||||
*/
|
||||
Multimap.prototype.delete = function(key, val) {
|
||||
if (!this.has(key))
|
||||
return false;
|
||||
|
||||
if (arguments.length == 1) {
|
||||
this._map ? (this._.delete(key)) : (delete this._[key]);
|
||||
return true;
|
||||
} else {
|
||||
var entry = this.get(key);
|
||||
var idx = entry.indexOf(val);
|
||||
if (idx != -1) {
|
||||
entry.splice(idx, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} key
|
||||
* @param {Object=} val
|
||||
* @return {boolean} whether the map contains 'key' or 'key=>val' pair
|
||||
*/
|
||||
Multimap.prototype.has = function(key, val) {
|
||||
var hasKey = this._map ? this._.has(key) : this._.hasOwnProperty(key);
|
||||
|
||||
if (arguments.length == 1 || !hasKey)
|
||||
return hasKey;
|
||||
|
||||
var entry = this.get(key) || [];
|
||||
return entry.indexOf(val) != -1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array} all the keys in the map
|
||||
*/
|
||||
Multimap.prototype.keys = function() {
|
||||
if (this._map)
|
||||
return makeIterator(this._.keys());
|
||||
|
||||
return makeIterator(Object.keys(this._));
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Array} all the values in the map
|
||||
*/
|
||||
Multimap.prototype.values = function() {
|
||||
var vals = [];
|
||||
this.forEachEntry(function(entry) {
|
||||
Array.prototype.push.apply(vals, entry);
|
||||
});
|
||||
|
||||
return makeIterator(vals);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Multimap.prototype.forEachEntry = function(iter) {
|
||||
mapEach(this, iter);
|
||||
};
|
||||
|
||||
Multimap.prototype.forEach = function(iter) {
|
||||
var self = this;
|
||||
self.forEachEntry(function(entry, key) {
|
||||
entry.forEach(function(item) {
|
||||
iter(item, key, self);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Multimap.prototype.clear = function() {
|
||||
if (this._map) {
|
||||
this._.clear();
|
||||
} else {
|
||||
this._ = {};
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(
|
||||
Multimap.prototype,
|
||||
"size", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
var total = 0;
|
||||
|
||||
mapEach(this, function(value){
|
||||
total += value.length;
|
||||
});
|
||||
|
||||
return total;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(
|
||||
Multimap.prototype,
|
||||
"count", {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return this._.size;
|
||||
}
|
||||
});
|
||||
|
||||
var safariNext;
|
||||
|
||||
try{
|
||||
safariNext = new Function('iterator', 'makeIterator', 'var keysArray = []; for(var key of iterator){keysArray.push(key);} return makeIterator(keysArray).next;');
|
||||
}catch(error){
|
||||
// for of not implemented;
|
||||
}
|
||||
|
||||
function makeIterator(iterator){
|
||||
if(Array.isArray(iterator)){
|
||||
var nextIndex = 0;
|
||||
|
||||
return {
|
||||
next: function(){
|
||||
return nextIndex < iterator.length ?
|
||||
{value: iterator[nextIndex++], done: false} :
|
||||
{done: true};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Only an issue in safari
|
||||
if(!iterator.next && safariNext){
|
||||
iterator.next = safariNext(iterator, makeIterator);
|
||||
}
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
return Multimap;
|
||||
})();
|
||||
|
||||
|
||||
if(typeof exports === 'object' && module && module.exports)
|
||||
module.exports = Multimap;
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define(function() { return Multimap; });
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "multimap",
|
||||
"version": "1.1.0",
|
||||
"description": "multi-map which allow multiple values for the same key",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "./node_modules/.bin/jshint *.js test/*.js",
|
||||
"test": "npm run lint; node test/index.js;node test/es6map.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/villadora/multi-map.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/villadora/multi-map/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"keys",
|
||||
"map",
|
||||
"multiple"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"chai": "~1.7.2",
|
||||
"es6-shim": "^0.13.0",
|
||||
"jshint": "~2.1.9"
|
||||
},
|
||||
"readmeFilename": "README.md",
|
||||
"author": {
|
||||
"name": "villa.gao",
|
||||
"email": "jky239@gmail.com"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require('chai').assert;
|
||||
require('es6-shim');
|
||||
|
||||
var Multimap = require('..');
|
||||
|
||||
var map = new Multimap([
|
||||
['a', 'one'],
|
||||
['b', 1],
|
||||
['a', 'two'],
|
||||
['b', 2]
|
||||
]);
|
||||
|
||||
assert.equal(map.size, 4);
|
||||
|
||||
assert.equal(map.get('a').length, 2);
|
||||
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
|
||||
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
|
||||
|
||||
assert.equal(map.get('b').length, 2);
|
||||
assert.equal(map.get('b')[0], 1); // [1, 2]
|
||||
assert.equal(map.get('b')[1], 2); // [1, 2]
|
||||
|
||||
|
||||
assert(map.has('a'), "map contains key 'a'");
|
||||
assert(!map.has('foo'), "map does not contain key 'foo'");
|
||||
|
||||
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
|
||||
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
|
||||
|
||||
map.set('a', 'three');
|
||||
|
||||
assert.equal(map.size, 5);
|
||||
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
|
||||
|
||||
map.set('b', 3, 4);
|
||||
assert.equal(map.size, 7);
|
||||
|
||||
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
|
||||
assert.equal(map.size, 6);
|
||||
assert(!map.delete('x'), "empty 'x' for delete");
|
||||
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
|
||||
assert(map.delete('b'), "delete all 'b'");
|
||||
|
||||
assert.equal(map.size, 2);
|
||||
|
||||
map.set('b', 1, 2);
|
||||
assert.equal(map.size, 4); // 4
|
||||
|
||||
var cnt = 0;
|
||||
map.forEach(function(value, key) {
|
||||
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
});
|
||||
|
||||
assert.equal(cnt, 4);
|
||||
|
||||
cnt = 0;
|
||||
map.forEachEntry(function(entry, key) {
|
||||
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
assert.equal(entry.length, 2);
|
||||
});
|
||||
|
||||
assert.equal(cnt, 2);
|
||||
|
||||
|
||||
|
||||
var keys = map.keys(); // ['a', 'b']
|
||||
assert.equal(keys.next().value, 'a');
|
||||
assert.equal(keys.next().value, 'b');
|
||||
assert(keys.next().done);
|
||||
|
||||
var values = map.values(); // ['one', 'two', 1, 2]
|
||||
assert.equal(values.next().value, 'one');
|
||||
assert.equal(values.next().value, 'two');
|
||||
assert.equal(values.next().value, 1);
|
||||
assert.equal(values.next().value, 2);
|
||||
assert(values.next().done);
|
||||
|
||||
map.clear();
|
||||
|
||||
assert.equal(map.size, 0);
|
|
@ -0,0 +1,91 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var Multimap = require('..');
|
||||
|
||||
var map = new Multimap([
|
||||
['a', 'one'],
|
||||
['b', 1],
|
||||
['a', 'two'],
|
||||
['b', 2]
|
||||
]);
|
||||
|
||||
assert.equal(map.size, 4);
|
||||
assert.equal(map.count, 2);
|
||||
|
||||
assert.equal(map.get('a').length, 2);
|
||||
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
|
||||
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
|
||||
|
||||
assert.equal(map.get('b').length, 2);
|
||||
assert.equal(map.get('b')[0], 1); // [1, 2]
|
||||
assert.equal(map.get('b')[1], 2); // [1, 2]
|
||||
|
||||
|
||||
assert(map.has('a'), "map contains key 'a'");
|
||||
assert(!map.has('foo'), "map does not contain key 'foo'");
|
||||
|
||||
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
|
||||
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
|
||||
|
||||
map.set('a', 'three');
|
||||
|
||||
assert.equal(map.size, 5);
|
||||
assert.equal(map.count, 2);
|
||||
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
|
||||
|
||||
map.set('b', 3, 4);
|
||||
assert.equal(map.size, 7);
|
||||
assert.equal(map.count, 2);
|
||||
|
||||
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
|
||||
assert.equal(map.size, 6);
|
||||
assert.equal(map.count, 2);
|
||||
assert(!map.delete('x'), "empty 'x' for delete");
|
||||
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
|
||||
assert(map.delete('b'), "delete all 'b'");
|
||||
|
||||
assert.equal(map.size, 2);
|
||||
assert.equal(map.count, 1);
|
||||
|
||||
map.set('b', 1, 2);
|
||||
assert.equal(map.size, 4); // 4
|
||||
assert.equal(map.count, 2);
|
||||
|
||||
var cnt = 0;
|
||||
map.forEach(function(value, key) {
|
||||
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
});
|
||||
|
||||
assert.equal(cnt, 4);
|
||||
|
||||
cnt = 0;
|
||||
map.forEachEntry(function(entry, key) {
|
||||
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
assert.equal(entry.length, 2);
|
||||
});
|
||||
|
||||
assert.equal(cnt, 2);
|
||||
|
||||
|
||||
var keys = map.keys(); // ['a', 'b']
|
||||
assert.equal(keys.next().value, 'a');
|
||||
assert.equal(keys.next().value, 'b');
|
||||
assert(keys.next().done);
|
||||
|
||||
var values = map.values(); // ['one', 'two', 1, 2]
|
||||
assert.equal(values.next().value, 'one');
|
||||
assert.equal(values.next().value, 'two');
|
||||
assert.equal(values.next().value, 1);
|
||||
assert.equal(values.next().value, 2);
|
||||
assert(values.next().done);
|
||||
|
||||
|
||||
map.clear();
|
||||
|
||||
assert.equal(map.size, 0);
|
||||
assert.equal(map.count, 0);
|
|
@ -0,0 +1,92 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>MultiMap Tests</title>
|
||||
<script src="../node_modules/chai/chai.js"></script>
|
||||
<script src="../index.js"></script>
|
||||
<script type="text/javascript">
|
||||
var assert = chai.assert;
|
||||
var map = new Multimap([
|
||||
['a', 'one'],
|
||||
['b', 1],
|
||||
['a', 'two'],
|
||||
['b', 2]
|
||||
]);
|
||||
|
||||
assert.equal(map.size, 4);
|
||||
|
||||
assert.equal(map.get('a').length, 2);
|
||||
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
|
||||
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
|
||||
|
||||
assert.equal(map.get('b').length, 2);
|
||||
assert.equal(map.get('b')[0], 1); // [1, 2]
|
||||
assert.equal(map.get('b')[1], 2); // [1, 2]
|
||||
|
||||
|
||||
assert(map.has('a'), "map contains key 'a'");
|
||||
assert(!map.has('foo'), "map does not contain key 'foo'");
|
||||
|
||||
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
|
||||
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
|
||||
|
||||
map.set('a', 'three');
|
||||
|
||||
assert.equal(map.size, 5);
|
||||
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
|
||||
|
||||
map.set('b', 3, 4);
|
||||
assert.equal(map.size, 7);
|
||||
|
||||
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
|
||||
assert.equal(map.size, 6);
|
||||
assert(!map.delete('x'), "empty 'x' for delete");
|
||||
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
|
||||
assert(map.delete('b'), "delete all 'b'");
|
||||
|
||||
assert.equal(map.size, 2);
|
||||
|
||||
map.set('b', 1, 2);
|
||||
assert.equal(map.size, 4); // 4
|
||||
|
||||
var cnt = 0;
|
||||
map.forEach(function(value, key) {
|
||||
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
});
|
||||
|
||||
assert.equal(cnt, 4);
|
||||
|
||||
cnt = 0;
|
||||
map.forEachEntry(function(entry, key) {
|
||||
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
|
||||
cnt++;
|
||||
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
|
||||
assert.equal(entry.length, 2);
|
||||
});
|
||||
|
||||
assert.equal(cnt, 2);
|
||||
|
||||
|
||||
var keys = map.keys(); // ['a', 'b']
|
||||
assert.equal(keys.next().value, 'a');
|
||||
assert.equal(keys.next().value, 'b');
|
||||
assert(keys.next().done);
|
||||
|
||||
var values = map.values(); // ['one', 'two', 1, 2]
|
||||
assert.equal(values.next().value, 'one');
|
||||
assert.equal(values.next().value, 'two');
|
||||
assert.equal(values.next().value, 1);
|
||||
assert.equal(values.next().value, 2);
|
||||
assert(values.next().done);
|
||||
|
||||
|
||||
map.clear();
|
||||
|
||||
assert.equal(map.size, 0);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,63 @@
|
|||
Shift AST Constructors
|
||||
======================
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This project provides constructors for
|
||||
[Shift format](https://github.com/shapesecurity/shift-spec) AST nodes.
|
||||
|
||||
The resulting objects are suitable for use with the rest of the [Shift suite](http://shift-ast.org/).
|
||||
|
||||
There is a version with typechecking available as `shift-ast/checked` for use during development.
|
||||
|
||||
## Status
|
||||
|
||||
[Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install shift-ast
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var AST = require("shift-ast"); // or "shift-ast/checked"
|
||||
var myAstFragment = new AST.LabeledStatement({
|
||||
label: "label",
|
||||
body: new AST.EmptyStatement
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
* Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
|
||||
* Fork this repo, and clone the forked repo.
|
||||
* Install dependencies with `npm install`.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Create a feature branch. Make your changes. Add tests.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
|
||||
* Open a Pull Request on Github.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2014 Shape Security, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright 2016 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
module.exports = require('./gen/checked');
|
|
@ -0,0 +1,19 @@
|
|||
// Generated by scripts/generate-dts.js.
|
||||
|
||||
/**
|
||||
* Copyright 2019 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './index';
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,707 @@
|
|||
// Generated by scripts/generate-dts.js.
|
||||
|
||||
/**
|
||||
* Copyright 2019 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
type Init<Node> = Pick<Node, Exclude<keyof Node, 'type'>>;
|
||||
|
||||
export type Node = ArrayAssignmentTarget | ArrayBinding | ArrayExpression | ArrowExpression | AssignmentExpression | AssignmentTargetIdentifier | AssignmentTargetPropertyIdentifier | AssignmentTargetPropertyProperty | AssignmentTargetWithDefault | AwaitExpression | BinaryExpression | BindingIdentifier | BindingPropertyIdentifier | BindingPropertyProperty | BindingWithDefault | Block | BlockStatement | BreakStatement | CallExpression | CatchClause | ClassDeclaration | ClassElement | ClassExpression | CompoundAssignmentExpression | ComputedMemberAssignmentTarget | ComputedMemberExpression | ComputedPropertyName | ConditionalExpression | ContinueStatement | DataProperty | DebuggerStatement | Directive | DoWhileStatement | EmptyStatement | Export | ExportAllFrom | ExportDefault | ExportFrom | ExportFromSpecifier | ExportLocalSpecifier | ExportLocals | ExpressionStatement | ForAwaitStatement | ForInStatement | ForOfStatement | ForStatement | FormalParameters | FunctionBody | FunctionDeclaration | FunctionExpression | Getter | IdentifierExpression | IfStatement | Import | ImportNamespace | ImportSpecifier | LabeledStatement | LiteralBooleanExpression | LiteralInfinityExpression | LiteralNullExpression | LiteralNumericExpression | LiteralRegExpExpression | LiteralStringExpression | Method | Module | NewExpression | NewTargetExpression | ObjectAssignmentTarget | ObjectBinding | ObjectExpression | ReturnStatement | Script | Setter | ShorthandProperty | SpreadElement | SpreadProperty | StaticMemberAssignmentTarget | StaticMemberExpression | StaticPropertyName | Super | SwitchCase | SwitchDefault | SwitchStatement | SwitchStatementWithDefault | TemplateElement | TemplateExpression | ThisExpression | ThrowStatement | TryCatchStatement | TryFinallyStatement | UnaryExpression | UpdateExpression | VariableDeclaration | VariableDeclarationStatement | VariableDeclarator | WhileStatement | WithStatement | YieldExpression | YieldGeneratorExpression;
|
||||
|
||||
export type Expression = ArrayExpression | ArrowExpression | AssignmentExpression | AwaitExpression | BinaryExpression | CallExpression | ClassExpression | CompoundAssignmentExpression | ConditionalExpression | FunctionExpression | IdentifierExpression | LiteralBooleanExpression | LiteralInfinityExpression | LiteralNullExpression | LiteralNumericExpression | LiteralRegExpExpression | LiteralStringExpression | ComputedMemberExpression | StaticMemberExpression | NewExpression | NewTargetExpression | ObjectExpression | TemplateExpression | ThisExpression | UnaryExpression | UpdateExpression | YieldExpression | YieldGeneratorExpression;
|
||||
|
||||
export type Statement = BlockStatement | BreakStatement | ClassDeclaration | ContinueStatement | DebuggerStatement | EmptyStatement | ExpressionStatement | FunctionDeclaration | IfStatement | DoWhileStatement | ForAwaitStatement | ForInStatement | ForOfStatement | ForStatement | WhileStatement | LabeledStatement | ReturnStatement | SwitchStatement | SwitchStatementWithDefault | ThrowStatement | TryCatchStatement | TryFinallyStatement | VariableDeclarationStatement | WithStatement;
|
||||
|
||||
|
||||
export class ArrayAssignmentTarget {
|
||||
type: 'ArrayAssignmentTarget';
|
||||
elements: Array<AssignmentTargetWithDefault | ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | null>;
|
||||
rest: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | null;
|
||||
constructor(init: Init<ArrayAssignmentTarget>);
|
||||
}
|
||||
|
||||
export class ArrayBinding {
|
||||
type: 'ArrayBinding';
|
||||
elements: Array<BindingWithDefault | BindingIdentifier | ArrayBinding | ObjectBinding | null>;
|
||||
rest: BindingIdentifier | ArrayBinding | ObjectBinding | null;
|
||||
constructor(init: Init<ArrayBinding>);
|
||||
}
|
||||
|
||||
export class ArrayExpression {
|
||||
type: 'ArrayExpression';
|
||||
elements: Array<Expression | SpreadElement | null>;
|
||||
constructor(init: Init<ArrayExpression>);
|
||||
}
|
||||
|
||||
export class ArrowExpression {
|
||||
type: 'ArrowExpression';
|
||||
isAsync: boolean;
|
||||
params: FormalParameters;
|
||||
body: Expression | FunctionBody;
|
||||
constructor(init: Init<ArrowExpression>);
|
||||
}
|
||||
|
||||
export class AssignmentExpression {
|
||||
type: 'AssignmentExpression';
|
||||
binding: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget;
|
||||
expression: Expression;
|
||||
constructor(init: Init<AssignmentExpression>);
|
||||
}
|
||||
|
||||
export class AssignmentTargetIdentifier {
|
||||
type: 'AssignmentTargetIdentifier';
|
||||
name: string;
|
||||
constructor(init: Init<AssignmentTargetIdentifier>);
|
||||
}
|
||||
|
||||
export class AssignmentTargetPropertyIdentifier {
|
||||
type: 'AssignmentTargetPropertyIdentifier';
|
||||
binding: AssignmentTargetIdentifier;
|
||||
init: Expression | null;
|
||||
constructor(init: Init<AssignmentTargetPropertyIdentifier>);
|
||||
}
|
||||
|
||||
export class AssignmentTargetPropertyProperty {
|
||||
type: 'AssignmentTargetPropertyProperty';
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
binding: AssignmentTargetWithDefault | ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget;
|
||||
constructor(init: Init<AssignmentTargetPropertyProperty>);
|
||||
}
|
||||
|
||||
export class AssignmentTargetWithDefault {
|
||||
type: 'AssignmentTargetWithDefault';
|
||||
binding: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget;
|
||||
init: Expression;
|
||||
constructor(init: Init<AssignmentTargetWithDefault>);
|
||||
}
|
||||
|
||||
export class AwaitExpression {
|
||||
type: 'AwaitExpression';
|
||||
expression: Expression;
|
||||
constructor(init: Init<AwaitExpression>);
|
||||
}
|
||||
|
||||
export class BinaryExpression {
|
||||
type: 'BinaryExpression';
|
||||
left: Expression;
|
||||
operator: '==' | '!=' | '===' | '!==' | '<' | '<=' | '>' | '>=' | 'in' | 'instanceof' | '<<' | '>>' | '>>>' | '+' | '-' | '*' | '/' | '%' | '**' | ',' | '||' | '&&' | '|' | '^' | '&';
|
||||
right: Expression;
|
||||
constructor(init: Init<BinaryExpression>);
|
||||
}
|
||||
|
||||
export class BindingIdentifier {
|
||||
type: 'BindingIdentifier';
|
||||
name: string;
|
||||
constructor(init: Init<BindingIdentifier>);
|
||||
}
|
||||
|
||||
export class BindingPropertyIdentifier {
|
||||
type: 'BindingPropertyIdentifier';
|
||||
binding: BindingIdentifier;
|
||||
init: Expression | null;
|
||||
constructor(init: Init<BindingPropertyIdentifier>);
|
||||
}
|
||||
|
||||
export class BindingPropertyProperty {
|
||||
type: 'BindingPropertyProperty';
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
binding: BindingWithDefault | BindingIdentifier | ArrayBinding | ObjectBinding;
|
||||
constructor(init: Init<BindingPropertyProperty>);
|
||||
}
|
||||
|
||||
export class BindingWithDefault {
|
||||
type: 'BindingWithDefault';
|
||||
binding: BindingIdentifier | ArrayBinding | ObjectBinding;
|
||||
init: Expression;
|
||||
constructor(init: Init<BindingWithDefault>);
|
||||
}
|
||||
|
||||
export class Block {
|
||||
type: 'Block';
|
||||
statements: Array<Statement>;
|
||||
constructor(init: Init<Block>);
|
||||
}
|
||||
|
||||
export class BlockStatement {
|
||||
type: 'BlockStatement';
|
||||
block: Block;
|
||||
constructor(init: Init<BlockStatement>);
|
||||
}
|
||||
|
||||
export class BreakStatement {
|
||||
type: 'BreakStatement';
|
||||
label: string | null;
|
||||
constructor(init: Init<BreakStatement>);
|
||||
}
|
||||
|
||||
export class CallExpression {
|
||||
type: 'CallExpression';
|
||||
callee: Expression | Super;
|
||||
arguments: Array<Expression | SpreadElement>;
|
||||
constructor(init: Init<CallExpression>);
|
||||
}
|
||||
|
||||
export class CatchClause {
|
||||
type: 'CatchClause';
|
||||
binding: BindingIdentifier | ArrayBinding | ObjectBinding | null;
|
||||
body: Block;
|
||||
constructor(init: Init<CatchClause>);
|
||||
}
|
||||
|
||||
export class ClassDeclaration {
|
||||
type: 'ClassDeclaration';
|
||||
name: BindingIdentifier;
|
||||
super: Expression | null;
|
||||
elements: Array<ClassElement>;
|
||||
constructor(init: Init<ClassDeclaration>);
|
||||
}
|
||||
|
||||
export class ClassElement {
|
||||
type: 'ClassElement';
|
||||
isStatic: boolean;
|
||||
method: Getter | Method | Setter;
|
||||
constructor(init: Init<ClassElement>);
|
||||
}
|
||||
|
||||
export class ClassExpression {
|
||||
type: 'ClassExpression';
|
||||
name: BindingIdentifier | null;
|
||||
super: Expression | null;
|
||||
elements: Array<ClassElement>;
|
||||
constructor(init: Init<ClassExpression>);
|
||||
}
|
||||
|
||||
export class CompoundAssignmentExpression {
|
||||
type: 'CompoundAssignmentExpression';
|
||||
binding: AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget;
|
||||
operator: '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '<<=' | '>>=' | '>>>=' | '|=' | '^=' | '&=';
|
||||
expression: Expression;
|
||||
constructor(init: Init<CompoundAssignmentExpression>);
|
||||
}
|
||||
|
||||
export class ComputedMemberAssignmentTarget {
|
||||
type: 'ComputedMemberAssignmentTarget';
|
||||
object: Expression | Super;
|
||||
expression: Expression;
|
||||
constructor(init: Init<ComputedMemberAssignmentTarget>);
|
||||
}
|
||||
|
||||
export class ComputedMemberExpression {
|
||||
type: 'ComputedMemberExpression';
|
||||
object: Expression | Super;
|
||||
expression: Expression;
|
||||
constructor(init: Init<ComputedMemberExpression>);
|
||||
}
|
||||
|
||||
export class ComputedPropertyName {
|
||||
type: 'ComputedPropertyName';
|
||||
expression: Expression;
|
||||
constructor(init: Init<ComputedPropertyName>);
|
||||
}
|
||||
|
||||
export class ConditionalExpression {
|
||||
type: 'ConditionalExpression';
|
||||
test: Expression;
|
||||
consequent: Expression;
|
||||
alternate: Expression;
|
||||
constructor(init: Init<ConditionalExpression>);
|
||||
}
|
||||
|
||||
export class ContinueStatement {
|
||||
type: 'ContinueStatement';
|
||||
label: string | null;
|
||||
constructor(init: Init<ContinueStatement>);
|
||||
}
|
||||
|
||||
export class DataProperty {
|
||||
type: 'DataProperty';
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
expression: Expression;
|
||||
constructor(init: Init<DataProperty>);
|
||||
}
|
||||
|
||||
export class DebuggerStatement {
|
||||
type: 'DebuggerStatement';
|
||||
constructor(init?: Init<DebuggerStatement>);
|
||||
}
|
||||
|
||||
export class Directive {
|
||||
type: 'Directive';
|
||||
rawValue: string;
|
||||
constructor(init: Init<Directive>);
|
||||
}
|
||||
|
||||
export class DoWhileStatement {
|
||||
type: 'DoWhileStatement';
|
||||
body: Statement;
|
||||
test: Expression;
|
||||
constructor(init: Init<DoWhileStatement>);
|
||||
}
|
||||
|
||||
export class EmptyStatement {
|
||||
type: 'EmptyStatement';
|
||||
constructor(init?: Init<EmptyStatement>);
|
||||
}
|
||||
|
||||
export class Export {
|
||||
type: 'Export';
|
||||
declaration: ClassDeclaration | FunctionDeclaration | VariableDeclaration;
|
||||
constructor(init: Init<Export>);
|
||||
}
|
||||
|
||||
export class ExportAllFrom {
|
||||
type: 'ExportAllFrom';
|
||||
moduleSpecifier: string;
|
||||
constructor(init: Init<ExportAllFrom>);
|
||||
}
|
||||
|
||||
export class ExportDefault {
|
||||
type: 'ExportDefault';
|
||||
body: ClassDeclaration | Expression | FunctionDeclaration;
|
||||
constructor(init: Init<ExportDefault>);
|
||||
}
|
||||
|
||||
export class ExportFrom {
|
||||
type: 'ExportFrom';
|
||||
namedExports: Array<ExportFromSpecifier>;
|
||||
moduleSpecifier: string;
|
||||
constructor(init: Init<ExportFrom>);
|
||||
}
|
||||
|
||||
export class ExportFromSpecifier {
|
||||
type: 'ExportFromSpecifier';
|
||||
name: string;
|
||||
exportedName: string | null;
|
||||
constructor(init: Init<ExportFromSpecifier>);
|
||||
}
|
||||
|
||||
export class ExportLocalSpecifier {
|
||||
type: 'ExportLocalSpecifier';
|
||||
name: IdentifierExpression;
|
||||
exportedName: string | null;
|
||||
constructor(init: Init<ExportLocalSpecifier>);
|
||||
}
|
||||
|
||||
export class ExportLocals {
|
||||
type: 'ExportLocals';
|
||||
namedExports: Array<ExportLocalSpecifier>;
|
||||
constructor(init: Init<ExportLocals>);
|
||||
}
|
||||
|
||||
export class ExpressionStatement {
|
||||
type: 'ExpressionStatement';
|
||||
expression: Expression;
|
||||
constructor(init: Init<ExpressionStatement>);
|
||||
}
|
||||
|
||||
export class ForAwaitStatement {
|
||||
type: 'ForAwaitStatement';
|
||||
left: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | VariableDeclaration;
|
||||
right: Expression;
|
||||
body: Statement;
|
||||
constructor(init: Init<ForAwaitStatement>);
|
||||
}
|
||||
|
||||
export class ForInStatement {
|
||||
type: 'ForInStatement';
|
||||
left: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | VariableDeclaration;
|
||||
right: Expression;
|
||||
body: Statement;
|
||||
constructor(init: Init<ForInStatement>);
|
||||
}
|
||||
|
||||
export class ForOfStatement {
|
||||
type: 'ForOfStatement';
|
||||
left: ArrayAssignmentTarget | ObjectAssignmentTarget | AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | VariableDeclaration;
|
||||
right: Expression;
|
||||
body: Statement;
|
||||
constructor(init: Init<ForOfStatement>);
|
||||
}
|
||||
|
||||
export class ForStatement {
|
||||
type: 'ForStatement';
|
||||
init: Expression | VariableDeclaration | null;
|
||||
test: Expression | null;
|
||||
update: Expression | null;
|
||||
body: Statement;
|
||||
constructor(init: Init<ForStatement>);
|
||||
}
|
||||
|
||||
export class FormalParameters {
|
||||
type: 'FormalParameters';
|
||||
items: Array<BindingWithDefault | BindingIdentifier | ArrayBinding | ObjectBinding>;
|
||||
rest: BindingIdentifier | ArrayBinding | ObjectBinding | null;
|
||||
constructor(init: Init<FormalParameters>);
|
||||
}
|
||||
|
||||
export class FunctionBody {
|
||||
type: 'FunctionBody';
|
||||
directives: Array<Directive>;
|
||||
statements: Array<Statement>;
|
||||
constructor(init: Init<FunctionBody>);
|
||||
}
|
||||
|
||||
export class FunctionDeclaration {
|
||||
type: 'FunctionDeclaration';
|
||||
isAsync: boolean;
|
||||
isGenerator: boolean;
|
||||
name: BindingIdentifier;
|
||||
params: FormalParameters;
|
||||
body: FunctionBody;
|
||||
constructor(init: Init<FunctionDeclaration>);
|
||||
}
|
||||
|
||||
export class FunctionExpression {
|
||||
type: 'FunctionExpression';
|
||||
isAsync: boolean;
|
||||
isGenerator: boolean;
|
||||
name: BindingIdentifier | null;
|
||||
params: FormalParameters;
|
||||
body: FunctionBody;
|
||||
constructor(init: Init<FunctionExpression>);
|
||||
}
|
||||
|
||||
export class Getter {
|
||||
type: 'Getter';
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
body: FunctionBody;
|
||||
constructor(init: Init<Getter>);
|
||||
}
|
||||
|
||||
export class IdentifierExpression {
|
||||
type: 'IdentifierExpression';
|
||||
name: string;
|
||||
constructor(init: Init<IdentifierExpression>);
|
||||
}
|
||||
|
||||
export class IfStatement {
|
||||
type: 'IfStatement';
|
||||
test: Expression;
|
||||
consequent: Statement;
|
||||
alternate: Statement | null;
|
||||
constructor(init: Init<IfStatement>);
|
||||
}
|
||||
|
||||
export class Import {
|
||||
type: 'Import';
|
||||
defaultBinding: BindingIdentifier | null;
|
||||
namedImports: Array<ImportSpecifier>;
|
||||
moduleSpecifier: string;
|
||||
constructor(init: Init<Import>);
|
||||
}
|
||||
|
||||
export class ImportNamespace {
|
||||
type: 'ImportNamespace';
|
||||
defaultBinding: BindingIdentifier | null;
|
||||
namespaceBinding: BindingIdentifier;
|
||||
moduleSpecifier: string;
|
||||
constructor(init: Init<ImportNamespace>);
|
||||
}
|
||||
|
||||
export class ImportSpecifier {
|
||||
type: 'ImportSpecifier';
|
||||
name: string | null;
|
||||
binding: BindingIdentifier;
|
||||
constructor(init: Init<ImportSpecifier>);
|
||||
}
|
||||
|
||||
export class LabeledStatement {
|
||||
type: 'LabeledStatement';
|
||||
label: string;
|
||||
body: Statement;
|
||||
constructor(init: Init<LabeledStatement>);
|
||||
}
|
||||
|
||||
export class LiteralBooleanExpression {
|
||||
type: 'LiteralBooleanExpression';
|
||||
value: boolean;
|
||||
constructor(init: Init<LiteralBooleanExpression>);
|
||||
}
|
||||
|
||||
export class LiteralInfinityExpression {
|
||||
type: 'LiteralInfinityExpression';
|
||||
constructor(init?: Init<LiteralInfinityExpression>);
|
||||
}
|
||||
|
||||
export class LiteralNullExpression {
|
||||
type: 'LiteralNullExpression';
|
||||
constructor(init?: Init<LiteralNullExpression>);
|
||||
}
|
||||
|
||||
export class LiteralNumericExpression {
|
||||
type: 'LiteralNumericExpression';
|
||||
value: number;
|
||||
constructor(init: Init<LiteralNumericExpression>);
|
||||
}
|
||||
|
||||
export class LiteralRegExpExpression {
|
||||
type: 'LiteralRegExpExpression';
|
||||
pattern: string;
|
||||
global: boolean;
|
||||
ignoreCase: boolean;
|
||||
multiLine: boolean;
|
||||
dotAll: boolean;
|
||||
unicode: boolean;
|
||||
sticky: boolean;
|
||||
constructor(init: Init<LiteralRegExpExpression>);
|
||||
}
|
||||
|
||||
export class LiteralStringExpression {
|
||||
type: 'LiteralStringExpression';
|
||||
value: string;
|
||||
constructor(init: Init<LiteralStringExpression>);
|
||||
}
|
||||
|
||||
export class Method {
|
||||
type: 'Method';
|
||||
isAsync: boolean;
|
||||
isGenerator: boolean;
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
params: FormalParameters;
|
||||
body: FunctionBody;
|
||||
constructor(init: Init<Method>);
|
||||
}
|
||||
|
||||
export class Module {
|
||||
type: 'Module';
|
||||
directives: Array<Directive>;
|
||||
items: Array<Export | ExportAllFrom | ExportDefault | ExportFrom | ExportLocals | Import | ImportNamespace | Statement>;
|
||||
constructor(init: Init<Module>);
|
||||
}
|
||||
|
||||
export class NewExpression {
|
||||
type: 'NewExpression';
|
||||
callee: Expression;
|
||||
arguments: Array<Expression | SpreadElement>;
|
||||
constructor(init: Init<NewExpression>);
|
||||
}
|
||||
|
||||
export class NewTargetExpression {
|
||||
type: 'NewTargetExpression';
|
||||
constructor(init?: Init<NewTargetExpression>);
|
||||
}
|
||||
|
||||
export class ObjectAssignmentTarget {
|
||||
type: 'ObjectAssignmentTarget';
|
||||
properties: Array<AssignmentTargetPropertyIdentifier | AssignmentTargetPropertyProperty>;
|
||||
rest: AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget | null;
|
||||
constructor(init: Init<ObjectAssignmentTarget>);
|
||||
}
|
||||
|
||||
export class ObjectBinding {
|
||||
type: 'ObjectBinding';
|
||||
properties: Array<BindingPropertyIdentifier | BindingPropertyProperty>;
|
||||
rest: BindingIdentifier | null;
|
||||
constructor(init: Init<ObjectBinding>);
|
||||
}
|
||||
|
||||
export class ObjectExpression {
|
||||
type: 'ObjectExpression';
|
||||
properties: Array<DataProperty | Getter | Method | Setter | ShorthandProperty | SpreadProperty>;
|
||||
constructor(init: Init<ObjectExpression>);
|
||||
}
|
||||
|
||||
export class ReturnStatement {
|
||||
type: 'ReturnStatement';
|
||||
expression: Expression | null;
|
||||
constructor(init: Init<ReturnStatement>);
|
||||
}
|
||||
|
||||
export class Script {
|
||||
type: 'Script';
|
||||
directives: Array<Directive>;
|
||||
statements: Array<Statement>;
|
||||
constructor(init: Init<Script>);
|
||||
}
|
||||
|
||||
export class Setter {
|
||||
type: 'Setter';
|
||||
name: ComputedPropertyName | StaticPropertyName;
|
||||
param: BindingWithDefault | BindingIdentifier | ArrayBinding | ObjectBinding;
|
||||
body: FunctionBody;
|
||||
constructor(init: Init<Setter>);
|
||||
}
|
||||
|
||||
export class ShorthandProperty {
|
||||
type: 'ShorthandProperty';
|
||||
name: IdentifierExpression;
|
||||
constructor(init: Init<ShorthandProperty>);
|
||||
}
|
||||
|
||||
export class SpreadElement {
|
||||
type: 'SpreadElement';
|
||||
expression: Expression;
|
||||
constructor(init: Init<SpreadElement>);
|
||||
}
|
||||
|
||||
export class SpreadProperty {
|
||||
type: 'SpreadProperty';
|
||||
expression: Expression;
|
||||
constructor(init: Init<SpreadProperty>);
|
||||
}
|
||||
|
||||
export class StaticMemberAssignmentTarget {
|
||||
type: 'StaticMemberAssignmentTarget';
|
||||
object: Expression | Super;
|
||||
property: string;
|
||||
constructor(init: Init<StaticMemberAssignmentTarget>);
|
||||
}
|
||||
|
||||
export class StaticMemberExpression {
|
||||
type: 'StaticMemberExpression';
|
||||
object: Expression | Super;
|
||||
property: string;
|
||||
constructor(init: Init<StaticMemberExpression>);
|
||||
}
|
||||
|
||||
export class StaticPropertyName {
|
||||
type: 'StaticPropertyName';
|
||||
value: string;
|
||||
constructor(init: Init<StaticPropertyName>);
|
||||
}
|
||||
|
||||
export class Super {
|
||||
type: 'Super';
|
||||
constructor(init?: Init<Super>);
|
||||
}
|
||||
|
||||
export class SwitchCase {
|
||||
type: 'SwitchCase';
|
||||
test: Expression;
|
||||
consequent: Array<Statement>;
|
||||
constructor(init: Init<SwitchCase>);
|
||||
}
|
||||
|
||||
export class SwitchDefault {
|
||||
type: 'SwitchDefault';
|
||||
consequent: Array<Statement>;
|
||||
constructor(init: Init<SwitchDefault>);
|
||||
}
|
||||
|
||||
export class SwitchStatement {
|
||||
type: 'SwitchStatement';
|
||||
discriminant: Expression;
|
||||
cases: Array<SwitchCase>;
|
||||
constructor(init: Init<SwitchStatement>);
|
||||
}
|
||||
|
||||
export class SwitchStatementWithDefault {
|
||||
type: 'SwitchStatementWithDefault';
|
||||
discriminant: Expression;
|
||||
preDefaultCases: Array<SwitchCase>;
|
||||
defaultCase: SwitchDefault;
|
||||
postDefaultCases: Array<SwitchCase>;
|
||||
constructor(init: Init<SwitchStatementWithDefault>);
|
||||
}
|
||||
|
||||
export class TemplateElement {
|
||||
type: 'TemplateElement';
|
||||
rawValue: string;
|
||||
constructor(init: Init<TemplateElement>);
|
||||
}
|
||||
|
||||
export class TemplateExpression {
|
||||
type: 'TemplateExpression';
|
||||
tag: Expression | null;
|
||||
elements: Array<Expression | TemplateElement>;
|
||||
constructor(init: Init<TemplateExpression>);
|
||||
}
|
||||
|
||||
export class ThisExpression {
|
||||
type: 'ThisExpression';
|
||||
constructor(init?: Init<ThisExpression>);
|
||||
}
|
||||
|
||||
export class ThrowStatement {
|
||||
type: 'ThrowStatement';
|
||||
expression: Expression;
|
||||
constructor(init: Init<ThrowStatement>);
|
||||
}
|
||||
|
||||
export class TryCatchStatement {
|
||||
type: 'TryCatchStatement';
|
||||
body: Block;
|
||||
catchClause: CatchClause;
|
||||
constructor(init: Init<TryCatchStatement>);
|
||||
}
|
||||
|
||||
export class TryFinallyStatement {
|
||||
type: 'TryFinallyStatement';
|
||||
body: Block;
|
||||
catchClause: CatchClause | null;
|
||||
finalizer: Block;
|
||||
constructor(init: Init<TryFinallyStatement>);
|
||||
}
|
||||
|
||||
export class UnaryExpression {
|
||||
type: 'UnaryExpression';
|
||||
operator: '+' | '-' | '!' | '~' | 'typeof' | 'void' | 'delete';
|
||||
operand: Expression;
|
||||
constructor(init: Init<UnaryExpression>);
|
||||
}
|
||||
|
||||
export class UpdateExpression {
|
||||
type: 'UpdateExpression';
|
||||
isPrefix: boolean;
|
||||
operator: '++' | '--';
|
||||
operand: AssignmentTargetIdentifier | ComputedMemberAssignmentTarget | StaticMemberAssignmentTarget;
|
||||
constructor(init: Init<UpdateExpression>);
|
||||
}
|
||||
|
||||
export class VariableDeclaration {
|
||||
type: 'VariableDeclaration';
|
||||
kind: 'var' | 'let' | 'const';
|
||||
declarators: Array<VariableDeclarator>;
|
||||
constructor(init: Init<VariableDeclaration>);
|
||||
}
|
||||
|
||||
export class VariableDeclarationStatement {
|
||||
type: 'VariableDeclarationStatement';
|
||||
declaration: VariableDeclaration;
|
||||
constructor(init: Init<VariableDeclarationStatement>);
|
||||
}
|
||||
|
||||
export class VariableDeclarator {
|
||||
type: 'VariableDeclarator';
|
||||
binding: BindingIdentifier | ArrayBinding | ObjectBinding;
|
||||
init: Expression | null;
|
||||
constructor(init: Init<VariableDeclarator>);
|
||||
}
|
||||
|
||||
export class WhileStatement {
|
||||
type: 'WhileStatement';
|
||||
test: Expression;
|
||||
body: Statement;
|
||||
constructor(init: Init<WhileStatement>);
|
||||
}
|
||||
|
||||
export class WithStatement {
|
||||
type: 'WithStatement';
|
||||
object: Expression;
|
||||
body: Statement;
|
||||
constructor(init: Init<WithStatement>);
|
||||
}
|
||||
|
||||
export class YieldExpression {
|
||||
type: 'YieldExpression';
|
||||
expression: Expression | null;
|
||||
constructor(init: Init<YieldExpression>);
|
||||
}
|
||||
|
||||
export class YieldGeneratorExpression {
|
||||
type: 'YieldGeneratorExpression';
|
||||
expression: Expression;
|
||||
constructor(init: Init<YieldGeneratorExpression>);
|
||||
}
|
|
@ -0,0 +1,797 @@
|
|||
// Generated by scripts/generate.js.
|
||||
|
||||
/**
|
||||
* Copyright 2016 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
exports.ArrayAssignmentTarget = class {
|
||||
constructor({ elements, rest }) {
|
||||
this.type = 'ArrayAssignmentTarget';
|
||||
this.elements = elements;
|
||||
this.rest = rest;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ArrayBinding = class {
|
||||
constructor({ elements, rest }) {
|
||||
this.type = 'ArrayBinding';
|
||||
this.elements = elements;
|
||||
this.rest = rest;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ArrayExpression = class {
|
||||
constructor({ elements }) {
|
||||
this.type = 'ArrayExpression';
|
||||
this.elements = elements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ArrowExpression = class {
|
||||
constructor({ isAsync, params, body }) {
|
||||
this.type = 'ArrowExpression';
|
||||
this.isAsync = isAsync;
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = class {
|
||||
constructor({ binding, expression }) {
|
||||
this.type = 'AssignmentExpression';
|
||||
this.binding = binding;
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentTargetIdentifier = class {
|
||||
constructor({ name }) {
|
||||
this.type = 'AssignmentTargetIdentifier';
|
||||
this.name = name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentTargetPropertyIdentifier = class {
|
||||
constructor({ binding, init }) {
|
||||
this.type = 'AssignmentTargetPropertyIdentifier';
|
||||
this.binding = binding;
|
||||
this.init = init;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentTargetPropertyProperty = class {
|
||||
constructor({ name, binding }) {
|
||||
this.type = 'AssignmentTargetPropertyProperty';
|
||||
this.name = name;
|
||||
this.binding = binding;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentTargetWithDefault = class {
|
||||
constructor({ binding, init }) {
|
||||
this.type = 'AssignmentTargetWithDefault';
|
||||
this.binding = binding;
|
||||
this.init = init;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AwaitExpression = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'AwaitExpression';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BinaryExpression = class {
|
||||
constructor({ left, operator, right }) {
|
||||
this.type = 'BinaryExpression';
|
||||
this.left = left;
|
||||
this.operator = operator;
|
||||
this.right = right;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BindingIdentifier = class {
|
||||
constructor({ name }) {
|
||||
this.type = 'BindingIdentifier';
|
||||
this.name = name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BindingPropertyIdentifier = class {
|
||||
constructor({ binding, init }) {
|
||||
this.type = 'BindingPropertyIdentifier';
|
||||
this.binding = binding;
|
||||
this.init = init;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BindingPropertyProperty = class {
|
||||
constructor({ name, binding }) {
|
||||
this.type = 'BindingPropertyProperty';
|
||||
this.name = name;
|
||||
this.binding = binding;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BindingWithDefault = class {
|
||||
constructor({ binding, init }) {
|
||||
this.type = 'BindingWithDefault';
|
||||
this.binding = binding;
|
||||
this.init = init;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Block = class {
|
||||
constructor({ statements }) {
|
||||
this.type = 'Block';
|
||||
this.statements = statements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BlockStatement = class {
|
||||
constructor({ block }) {
|
||||
this.type = 'BlockStatement';
|
||||
this.block = block;
|
||||
}
|
||||
};
|
||||
|
||||
exports.BreakStatement = class {
|
||||
constructor({ label }) {
|
||||
this.type = 'BreakStatement';
|
||||
this.label = label;
|
||||
}
|
||||
};
|
||||
|
||||
exports.CallExpression = class {
|
||||
constructor({ callee, arguments: _arguments }) {
|
||||
this.type = 'CallExpression';
|
||||
this.callee = callee;
|
||||
this.arguments = _arguments;
|
||||
}
|
||||
};
|
||||
|
||||
exports.CatchClause = class {
|
||||
constructor({ binding, body }) {
|
||||
this.type = 'CatchClause';
|
||||
this.binding = binding;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ClassDeclaration = class {
|
||||
constructor({ name, super: _super, elements }) {
|
||||
this.type = 'ClassDeclaration';
|
||||
this.name = name;
|
||||
this.super = _super;
|
||||
this.elements = elements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ClassElement = class {
|
||||
constructor({ isStatic, method }) {
|
||||
this.type = 'ClassElement';
|
||||
this.isStatic = isStatic;
|
||||
this.method = method;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ClassExpression = class {
|
||||
constructor({ name, super: _super, elements }) {
|
||||
this.type = 'ClassExpression';
|
||||
this.name = name;
|
||||
this.super = _super;
|
||||
this.elements = elements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.CompoundAssignmentExpression = class {
|
||||
constructor({ binding, operator, expression }) {
|
||||
this.type = 'CompoundAssignmentExpression';
|
||||
this.binding = binding;
|
||||
this.operator = operator;
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ComputedMemberAssignmentTarget = class {
|
||||
constructor({ object, expression }) {
|
||||
this.type = 'ComputedMemberAssignmentTarget';
|
||||
this.object = object;
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ComputedMemberExpression = class {
|
||||
constructor({ object, expression }) {
|
||||
this.type = 'ComputedMemberExpression';
|
||||
this.object = object;
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ComputedPropertyName = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'ComputedPropertyName';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ConditionalExpression = class {
|
||||
constructor({ test, consequent, alternate }) {
|
||||
this.type = 'ConditionalExpression';
|
||||
this.test = test;
|
||||
this.consequent = consequent;
|
||||
this.alternate = alternate;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ContinueStatement = class {
|
||||
constructor({ label }) {
|
||||
this.type = 'ContinueStatement';
|
||||
this.label = label;
|
||||
}
|
||||
};
|
||||
|
||||
exports.DataProperty = class {
|
||||
constructor({ name, expression }) {
|
||||
this.type = 'DataProperty';
|
||||
this.name = name;
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.DebuggerStatement = class {
|
||||
constructor() {
|
||||
this.type = 'DebuggerStatement';
|
||||
}
|
||||
};
|
||||
|
||||
exports.Directive = class {
|
||||
constructor({ rawValue }) {
|
||||
this.type = 'Directive';
|
||||
this.rawValue = rawValue;
|
||||
}
|
||||
};
|
||||
|
||||
exports.DoWhileStatement = class {
|
||||
constructor({ body, test }) {
|
||||
this.type = 'DoWhileStatement';
|
||||
this.body = body;
|
||||
this.test = test;
|
||||
}
|
||||
};
|
||||
|
||||
exports.EmptyStatement = class {
|
||||
constructor() {
|
||||
this.type = 'EmptyStatement';
|
||||
}
|
||||
};
|
||||
|
||||
exports.Export = class {
|
||||
constructor({ declaration }) {
|
||||
this.type = 'Export';
|
||||
this.declaration = declaration;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportAllFrom = class {
|
||||
constructor({ moduleSpecifier }) {
|
||||
this.type = 'ExportAllFrom';
|
||||
this.moduleSpecifier = moduleSpecifier;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportDefault = class {
|
||||
constructor({ body }) {
|
||||
this.type = 'ExportDefault';
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportFrom = class {
|
||||
constructor({ namedExports, moduleSpecifier }) {
|
||||
this.type = 'ExportFrom';
|
||||
this.namedExports = namedExports;
|
||||
this.moduleSpecifier = moduleSpecifier;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportFromSpecifier = class {
|
||||
constructor({ name, exportedName }) {
|
||||
this.type = 'ExportFromSpecifier';
|
||||
this.name = name;
|
||||
this.exportedName = exportedName;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportLocalSpecifier = class {
|
||||
constructor({ name, exportedName }) {
|
||||
this.type = 'ExportLocalSpecifier';
|
||||
this.name = name;
|
||||
this.exportedName = exportedName;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportLocals = class {
|
||||
constructor({ namedExports }) {
|
||||
this.type = 'ExportLocals';
|
||||
this.namedExports = namedExports;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'ExpressionStatement';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ForAwaitStatement = class {
|
||||
constructor({ left, right, body }) {
|
||||
this.type = 'ForAwaitStatement';
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ForInStatement = class {
|
||||
constructor({ left, right, body }) {
|
||||
this.type = 'ForInStatement';
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ForOfStatement = class {
|
||||
constructor({ left, right, body }) {
|
||||
this.type = 'ForOfStatement';
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ForStatement = class {
|
||||
constructor({ init, test, update, body }) {
|
||||
this.type = 'ForStatement';
|
||||
this.init = init;
|
||||
this.test = test;
|
||||
this.update = update;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.FormalParameters = class {
|
||||
constructor({ items, rest }) {
|
||||
this.type = 'FormalParameters';
|
||||
this.items = items;
|
||||
this.rest = rest;
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionBody = class {
|
||||
constructor({ directives, statements }) {
|
||||
this.type = 'FunctionBody';
|
||||
this.directives = directives;
|
||||
this.statements = statements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration = class {
|
||||
constructor({ isAsync, isGenerator, name, params, body }) {
|
||||
this.type = 'FunctionDeclaration';
|
||||
this.isAsync = isAsync;
|
||||
this.isGenerator = isGenerator;
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionExpression = class {
|
||||
constructor({ isAsync, isGenerator, name, params, body }) {
|
||||
this.type = 'FunctionExpression';
|
||||
this.isAsync = isAsync;
|
||||
this.isGenerator = isGenerator;
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Getter = class {
|
||||
constructor({ name, body }) {
|
||||
this.type = 'Getter';
|
||||
this.name = name;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.IdentifierExpression = class {
|
||||
constructor({ name }) {
|
||||
this.type = 'IdentifierExpression';
|
||||
this.name = name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.IfStatement = class {
|
||||
constructor({ test, consequent, alternate }) {
|
||||
this.type = 'IfStatement';
|
||||
this.test = test;
|
||||
this.consequent = consequent;
|
||||
this.alternate = alternate;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Import = class {
|
||||
constructor({ defaultBinding, namedImports, moduleSpecifier }) {
|
||||
this.type = 'Import';
|
||||
this.defaultBinding = defaultBinding;
|
||||
this.namedImports = namedImports;
|
||||
this.moduleSpecifier = moduleSpecifier;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ImportNamespace = class {
|
||||
constructor({ defaultBinding, namespaceBinding, moduleSpecifier }) {
|
||||
this.type = 'ImportNamespace';
|
||||
this.defaultBinding = defaultBinding;
|
||||
this.namespaceBinding = namespaceBinding;
|
||||
this.moduleSpecifier = moduleSpecifier;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ImportSpecifier = class {
|
||||
constructor({ name, binding }) {
|
||||
this.type = 'ImportSpecifier';
|
||||
this.name = name;
|
||||
this.binding = binding;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LabeledStatement = class {
|
||||
constructor({ label, body }) {
|
||||
this.type = 'LabeledStatement';
|
||||
this.label = label;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralBooleanExpression = class {
|
||||
constructor({ value }) {
|
||||
this.type = 'LiteralBooleanExpression';
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralInfinityExpression = class {
|
||||
constructor() {
|
||||
this.type = 'LiteralInfinityExpression';
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralNullExpression = class {
|
||||
constructor() {
|
||||
this.type = 'LiteralNullExpression';
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralNumericExpression = class {
|
||||
constructor({ value }) {
|
||||
this.type = 'LiteralNumericExpression';
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralRegExpExpression = class {
|
||||
constructor({ pattern, global, ignoreCase, multiLine, dotAll, unicode, sticky }) {
|
||||
this.type = 'LiteralRegExpExpression';
|
||||
this.pattern = pattern;
|
||||
this.global = global;
|
||||
this.ignoreCase = ignoreCase;
|
||||
this.multiLine = multiLine;
|
||||
this.dotAll = dotAll;
|
||||
this.unicode = unicode;
|
||||
this.sticky = sticky;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LiteralStringExpression = class {
|
||||
constructor({ value }) {
|
||||
this.type = 'LiteralStringExpression';
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Method = class {
|
||||
constructor({ isAsync, isGenerator, name, params, body }) {
|
||||
this.type = 'Method';
|
||||
this.isAsync = isAsync;
|
||||
this.isGenerator = isGenerator;
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Module = class {
|
||||
constructor({ directives, items }) {
|
||||
this.type = 'Module';
|
||||
this.directives = directives;
|
||||
this.items = items;
|
||||
}
|
||||
};
|
||||
|
||||
exports.NewExpression = class {
|
||||
constructor({ callee, arguments: _arguments }) {
|
||||
this.type = 'NewExpression';
|
||||
this.callee = callee;
|
||||
this.arguments = _arguments;
|
||||
}
|
||||
};
|
||||
|
||||
exports.NewTargetExpression = class {
|
||||
constructor() {
|
||||
this.type = 'NewTargetExpression';
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectAssignmentTarget = class {
|
||||
constructor({ properties, rest }) {
|
||||
this.type = 'ObjectAssignmentTarget';
|
||||
this.properties = properties;
|
||||
this.rest = rest;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectBinding = class {
|
||||
constructor({ properties, rest }) {
|
||||
this.type = 'ObjectBinding';
|
||||
this.properties = properties;
|
||||
this.rest = rest;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = class {
|
||||
constructor({ properties }) {
|
||||
this.type = 'ObjectExpression';
|
||||
this.properties = properties;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ReturnStatement = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'ReturnStatement';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Script = class {
|
||||
constructor({ directives, statements }) {
|
||||
this.type = 'Script';
|
||||
this.directives = directives;
|
||||
this.statements = statements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Setter = class {
|
||||
constructor({ name, param, body }) {
|
||||
this.type = 'Setter';
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ShorthandProperty = class {
|
||||
constructor({ name }) {
|
||||
this.type = 'ShorthandProperty';
|
||||
this.name = name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.SpreadElement = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'SpreadElement';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.SpreadProperty = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'SpreadProperty';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.StaticMemberAssignmentTarget = class {
|
||||
constructor({ object, property }) {
|
||||
this.type = 'StaticMemberAssignmentTarget';
|
||||
this.object = object;
|
||||
this.property = property;
|
||||
}
|
||||
};
|
||||
|
||||
exports.StaticMemberExpression = class {
|
||||
constructor({ object, property }) {
|
||||
this.type = 'StaticMemberExpression';
|
||||
this.object = object;
|
||||
this.property = property;
|
||||
}
|
||||
};
|
||||
|
||||
exports.StaticPropertyName = class {
|
||||
constructor({ value }) {
|
||||
this.type = 'StaticPropertyName';
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Super = class {
|
||||
constructor() {
|
||||
this.type = 'Super';
|
||||
}
|
||||
};
|
||||
|
||||
exports.SwitchCase = class {
|
||||
constructor({ test, consequent }) {
|
||||
this.type = 'SwitchCase';
|
||||
this.test = test;
|
||||
this.consequent = consequent;
|
||||
}
|
||||
};
|
||||
|
||||
exports.SwitchDefault = class {
|
||||
constructor({ consequent }) {
|
||||
this.type = 'SwitchDefault';
|
||||
this.consequent = consequent;
|
||||
}
|
||||
};
|
||||
|
||||
exports.SwitchStatement = class {
|
||||
constructor({ discriminant, cases }) {
|
||||
this.type = 'SwitchStatement';
|
||||
this.discriminant = discriminant;
|
||||
this.cases = cases;
|
||||
}
|
||||
};
|
||||
|
||||
exports.SwitchStatementWithDefault = class {
|
||||
constructor({ discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
this.type = 'SwitchStatementWithDefault';
|
||||
this.discriminant = discriminant;
|
||||
this.preDefaultCases = preDefaultCases;
|
||||
this.defaultCase = defaultCase;
|
||||
this.postDefaultCases = postDefaultCases;
|
||||
}
|
||||
};
|
||||
|
||||
exports.TemplateElement = class {
|
||||
constructor({ rawValue }) {
|
||||
this.type = 'TemplateElement';
|
||||
this.rawValue = rawValue;
|
||||
}
|
||||
};
|
||||
|
||||
exports.TemplateExpression = class {
|
||||
constructor({ tag, elements }) {
|
||||
this.type = 'TemplateExpression';
|
||||
this.tag = tag;
|
||||
this.elements = elements;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThisExpression = class {
|
||||
constructor() {
|
||||
this.type = 'ThisExpression';
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThrowStatement = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'ThrowStatement';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.TryCatchStatement = class {
|
||||
constructor({ body, catchClause }) {
|
||||
this.type = 'TryCatchStatement';
|
||||
this.body = body;
|
||||
this.catchClause = catchClause;
|
||||
}
|
||||
};
|
||||
|
||||
exports.TryFinallyStatement = class {
|
||||
constructor({ body, catchClause, finalizer }) {
|
||||
this.type = 'TryFinallyStatement';
|
||||
this.body = body;
|
||||
this.catchClause = catchClause;
|
||||
this.finalizer = finalizer;
|
||||
}
|
||||
};
|
||||
|
||||
exports.UnaryExpression = class {
|
||||
constructor({ operator, operand }) {
|
||||
this.type = 'UnaryExpression';
|
||||
this.operator = operator;
|
||||
this.operand = operand;
|
||||
}
|
||||
};
|
||||
|
||||
exports.UpdateExpression = class {
|
||||
constructor({ isPrefix, operator, operand }) {
|
||||
this.type = 'UpdateExpression';
|
||||
this.isPrefix = isPrefix;
|
||||
this.operator = operator;
|
||||
this.operand = operand;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = class {
|
||||
constructor({ kind, declarators }) {
|
||||
this.type = 'VariableDeclaration';
|
||||
this.kind = kind;
|
||||
this.declarators = declarators;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclarationStatement = class {
|
||||
constructor({ declaration }) {
|
||||
this.type = 'VariableDeclarationStatement';
|
||||
this.declaration = declaration;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclarator = class {
|
||||
constructor({ binding, init }) {
|
||||
this.type = 'VariableDeclarator';
|
||||
this.binding = binding;
|
||||
this.init = init;
|
||||
}
|
||||
};
|
||||
|
||||
exports.WhileStatement = class {
|
||||
constructor({ test, body }) {
|
||||
this.type = 'WhileStatement';
|
||||
this.test = test;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.WithStatement = class {
|
||||
constructor({ object, body }) {
|
||||
this.type = 'WithStatement';
|
||||
this.object = object;
|
||||
this.body = body;
|
||||
}
|
||||
};
|
||||
|
||||
exports.YieldExpression = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'YieldExpression';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
||||
|
||||
exports.YieldGeneratorExpression = class {
|
||||
constructor({ expression }) {
|
||||
this.type = 'YieldGeneratorExpression';
|
||||
this.expression = expression;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"name": "shift-ast",
|
||||
"version": "7.0.0",
|
||||
"description": "constructors for the Shift AST format",
|
||||
"author": "Shape Security",
|
||||
"homepage": "https://github.com/shapesecurity/shift-ast-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shapesecurity/shift-ast-js.git"
|
||||
},
|
||||
"main": "gen/index.js",
|
||||
"types": "gen/index.d.ts",
|
||||
"files": [
|
||||
"checked.js",
|
||||
"gen"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --inline-diffs --check-leaks --ui bdd --reporter dot test && tsc -p test",
|
||||
"build": "mkdirp gen && node scripts/generate.js && node scripts/generate-checked.js && node scripts/generate-dts.js",
|
||||
"lint": "eslint scripts gen test",
|
||||
"prepare": "rimraf gen && npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/assert": "^1.4.2",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"eslint": "^5.6.1",
|
||||
"esutils": "^2.0.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^8.1.3",
|
||||
"rimraf": "^2.6.3",
|
||||
"shift-spec": "2019.0.0",
|
||||
"typescript": "^3.3.3333"
|
||||
},
|
||||
"keywords": [
|
||||
"Shift",
|
||||
"AST",
|
||||
"node",
|
||||
"constructor",
|
||||
"class",
|
||||
"abstract",
|
||||
"syntax",
|
||||
"tree"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/shapesecurity/shift-ast-js/issues"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,83 @@
|
|||
Shift Parser
|
||||
============
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This module provides an [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
||||
parser that produces a [Shift format](https://github.com/shapesecurity/shift-spec) AST.
|
||||
|
||||
|
||||
## Status
|
||||
|
||||
[Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
|
||||
|
||||
The parser supports version 6 (release candidate 2) of the ECMA-262 standard.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install shift-parser
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```es6
|
||||
import parse from "shift-parser";
|
||||
let ast = parse("/* ECMAScript program text */");
|
||||
```
|
||||
|
||||
```es6
|
||||
import {parseScript, parseModule} from "shift-parser";
|
||||
let scriptAST = parseScript("/* ECMAScript Script text */");
|
||||
let moduleAST = parseModule("/* ECMAScript Module text */");
|
||||
```
|
||||
|
||||
Or in node.js:
|
||||
|
||||
```js
|
||||
var parseScript = require("shift-parser").parseScript;
|
||||
var scriptAST = parseScript("/* ECMAScript Script text */");
|
||||
```
|
||||
|
||||
|
||||
Location information is available in environments which support `WeakMap` via an alternative interface:
|
||||
|
||||
```js
|
||||
let {parseScriptWithLocation, parseModuleWithLocation} = require("shift-parser");
|
||||
let {tree, locations, comments} = parseScriptWithLocation("2 + 3 /* = 5 */");
|
||||
let threeNode = tree.statements[0].expression.right;
|
||||
locations.get(threeNode); // { start: { line: 1, column: 4, offset: 4 }, end: { line: 1, column: 5, offset: 5 } }
|
||||
comments; // [ { text: ' = 5 ', type: 'MultiLine', start: { line: 1, column: 6, offset: 6 }, end: { line: 1, column: 15, offset: 15 } } ]
|
||||
```
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
* Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
|
||||
* Fork this repo, and clone the forked repo.
|
||||
* Install dependencies with `npm install`.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Create a feature branch. Make your changes. Add tests.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
|
||||
* Open a Pull Request on Github.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2014 Shape Security, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
"name": "shift-parser",
|
||||
"version": "8.0.0",
|
||||
"description": "ECMAScript parser that produces a Shift format AST",
|
||||
"author": "Shape Security",
|
||||
"homepage": "https://github.com/shapesecurity/shift-parser-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shapesecurity/shift-parser-js.git"
|
||||
},
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "echo nothing to do",
|
||||
"clean": "rm -rf coverage .nyc_output",
|
||||
"test-specific": "mocha --inline-diffs --check-leaks --ui tdd --reporter dot --slow 200 --timeout 5000 --recursive test/$TEST",
|
||||
"test": "TEST=\"\" npm run test-specific",
|
||||
"coverage": "npm run build -- --plugins=istanbul && nyc --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test",
|
||||
"lint": "eslint src test",
|
||||
"benchmark": "node benchmark",
|
||||
"profile": "node --prof profile.js && node-tick-processor",
|
||||
"regenerate-unicode": "node scripts/generate-unicode-data.js > src/unicode.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"multimap": "^1.0.2",
|
||||
"shift-ast": "7.0.0",
|
||||
"shift-reducer": "7.0.0",
|
||||
"shift-regexp-acceptor": "3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "6.0.1",
|
||||
"angular": "1.7.4",
|
||||
"benchmark": "2.1.4",
|
||||
"eslint": "5.6.0",
|
||||
"esprima": "4.0.1",
|
||||
"everything.js": "1.0.3",
|
||||
"expect.js": "0.3.1",
|
||||
"microtime": "^3.0.0",
|
||||
"mocha": "8.1.3",
|
||||
"normalize-parser-test": "2.0.0",
|
||||
"nyc": "13.0.1",
|
||||
"regenerate": "^1.4.0",
|
||||
"shift-parser-expectations": "^2018.0.2",
|
||||
"shift-spec": "2019.0.0",
|
||||
"test262": "git+https://github.com/tc39/test262.git#8ed9947df1c4ea34fa1810067529df0806cc07ad",
|
||||
"test262-parser": "^2.0.7",
|
||||
"test262-parser-tests": "0.0.5",
|
||||
"tick": "0.1.1",
|
||||
"traceur": "0.0.111",
|
||||
"uglify-js": "3.4.9",
|
||||
"unicode-8.0.0": "^0.7.5"
|
||||
},
|
||||
"keywords": [
|
||||
"Shift",
|
||||
"AST",
|
||||
"node",
|
||||
"parser",
|
||||
"SpiderMonkey",
|
||||
"Parser",
|
||||
"API",
|
||||
"parse",
|
||||
"spider",
|
||||
"monkey",
|
||||
"abstract",
|
||||
"syntax",
|
||||
"tree"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/shapesecurity/shift-parser-js/issues"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"nyc": {
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"sourceMap": false,
|
||||
"instrument": false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,414 @@
|
|||
/**
|
||||
* Copyright 2014 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const MultiMap = require('multimap');
|
||||
|
||||
function addEach(thisMap, ...otherMaps) {
|
||||
otherMaps.forEach(otherMap => {
|
||||
otherMap.forEachEntry((v, k) => {
|
||||
thisMap.set.apply(thisMap, [k].concat(v));
|
||||
});
|
||||
});
|
||||
return thisMap;
|
||||
}
|
||||
|
||||
let identity; // initialised below EarlyErrorState
|
||||
|
||||
class EarlyErrorState {
|
||||
|
||||
constructor() {
|
||||
this.errors = [];
|
||||
// errors that are only errors in strict mode code
|
||||
this.strictErrors = [];
|
||||
|
||||
// Label values used in LabeledStatement nodes; cleared at function boundaries
|
||||
this.usedLabelNames = [];
|
||||
|
||||
// BreakStatement nodes; cleared at iteration; switch; and function boundaries
|
||||
this.freeBreakStatements = [];
|
||||
// ContinueStatement nodes; cleared at
|
||||
this.freeContinueStatements = [];
|
||||
|
||||
// labeled BreakStatement nodes; cleared at LabeledStatement with same Label and function boundaries
|
||||
this.freeLabeledBreakStatements = [];
|
||||
// labeled ContinueStatement nodes; cleared at labeled iteration statement with same Label and function boundaries
|
||||
this.freeLabeledContinueStatements = [];
|
||||
|
||||
// NewTargetExpression nodes; cleared at function (besides arrow expression) boundaries
|
||||
this.newTargetExpressions = [];
|
||||
|
||||
// BindingIdentifier nodes; cleared at containing declaration node
|
||||
this.boundNames = new MultiMap;
|
||||
// BindingIdentifiers that were found to be in a lexical binding position
|
||||
this.lexicallyDeclaredNames = new MultiMap;
|
||||
// BindingIdentifiers that were the name of a FunctionDeclaration
|
||||
this.functionDeclarationNames = new MultiMap;
|
||||
// BindingIdentifiers that were found to be in a variable binding position
|
||||
this.varDeclaredNames = new MultiMap;
|
||||
// BindingIdentifiers that were found to be in a variable binding position
|
||||
this.forOfVarDeclaredNames = [];
|
||||
|
||||
// Names that this module exports
|
||||
this.exportedNames = new MultiMap;
|
||||
// Locally declared names that are referenced in export declarations
|
||||
this.exportedBindings = new MultiMap;
|
||||
|
||||
// CallExpressions with Super callee
|
||||
this.superCallExpressions = [];
|
||||
// SuperCall expressions in the context of a Method named "constructor"
|
||||
this.superCallExpressionsInConstructorMethod = [];
|
||||
// MemberExpressions with Super object
|
||||
this.superPropertyExpressions = [];
|
||||
|
||||
// YieldExpression and YieldGeneratorExpression nodes; cleared at function boundaries
|
||||
this.yieldExpressions = [];
|
||||
// AwaitExpression nodes; cleared at function boundaries
|
||||
this.awaitExpressions = [];
|
||||
}
|
||||
|
||||
|
||||
addFreeBreakStatement(s) {
|
||||
this.freeBreakStatements.push(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
addFreeLabeledBreakStatement(s) {
|
||||
this.freeLabeledBreakStatements.push(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearFreeBreakStatements() {
|
||||
this.freeBreakStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
addFreeContinueStatement(s) {
|
||||
this.freeContinueStatements.push(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
addFreeLabeledContinueStatement(s) {
|
||||
this.freeLabeledContinueStatements.push(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearFreeContinueStatements() {
|
||||
this.freeContinueStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceFreeBreakStatementErrors(createError) {
|
||||
[].push.apply(this.errors, this.freeBreakStatements.map(createError));
|
||||
this.freeBreakStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceFreeLabeledBreakStatementErrors(createError) {
|
||||
[].push.apply(this.errors, this.freeLabeledBreakStatements.map(createError));
|
||||
this.freeLabeledBreakStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceFreeContinueStatementErrors(createError) {
|
||||
[].push.apply(this.errors, this.freeContinueStatements.map(createError));
|
||||
this.freeContinueStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceFreeLabeledContinueStatementErrors(createError) {
|
||||
[].push.apply(this.errors, this.freeLabeledContinueStatements.map(createError));
|
||||
this.freeLabeledContinueStatements = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
observeIterationLabel(label) {
|
||||
this.usedLabelNames.push(label);
|
||||
this.freeLabeledBreakStatements = this.freeLabeledBreakStatements.filter(s => s.label !== label);
|
||||
this.freeLabeledContinueStatements = this.freeLabeledContinueStatements.filter(s => s.label !== label);
|
||||
return this;
|
||||
}
|
||||
|
||||
observeNonIterationLabel(label) {
|
||||
this.usedLabelNames.push(label);
|
||||
this.freeLabeledBreakStatements = this.freeLabeledBreakStatements.filter(s => s.label !== label);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearUsedLabelNames() {
|
||||
this.usedLabelNames = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
observeSuperCallExpression(node) {
|
||||
this.superCallExpressions.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
observeConstructorMethod() {
|
||||
this.superCallExpressionsInConstructorMethod = this.superCallExpressions;
|
||||
this.superCallExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
clearSuperCallExpressionsInConstructorMethod() {
|
||||
this.superCallExpressionsInConstructorMethod = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceSuperCallExpressions(createError) {
|
||||
[].push.apply(this.errors, this.superCallExpressions.map(createError));
|
||||
[].push.apply(this.errors, this.superCallExpressionsInConstructorMethod.map(createError));
|
||||
this.superCallExpressions = [];
|
||||
this.superCallExpressionsInConstructorMethod = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceSuperCallExpressionsInConstructorMethod(createError) {
|
||||
[].push.apply(this.errors, this.superCallExpressionsInConstructorMethod.map(createError));
|
||||
this.superCallExpressionsInConstructorMethod = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
observeSuperPropertyExpression(node) {
|
||||
this.superPropertyExpressions.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearSuperPropertyExpressions() {
|
||||
this.superPropertyExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceSuperPropertyExpressions(createError) {
|
||||
[].push.apply(this.errors, this.superPropertyExpressions.map(createError));
|
||||
this.superPropertyExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
observeNewTargetExpression(node) {
|
||||
this.newTargetExpressions.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearNewTargetExpressions() {
|
||||
this.newTargetExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
bindName(name, node) {
|
||||
this.boundNames.set(name, node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearBoundNames() {
|
||||
this.boundNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
observeLexicalDeclaration() {
|
||||
addEach(this.lexicallyDeclaredNames, this.boundNames);
|
||||
this.boundNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
observeLexicalBoundary() {
|
||||
this.previousLexicallyDeclaredNames = this.lexicallyDeclaredNames;
|
||||
this.lexicallyDeclaredNames = new MultiMap;
|
||||
this.functionDeclarationNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceDuplicateLexicallyDeclaredNames(createError) {
|
||||
this.lexicallyDeclaredNames.forEachEntry(nodes => {
|
||||
if (nodes.length > 1) {
|
||||
nodes.slice(1).forEach(dupeNode => {
|
||||
this.addError(createError(dupeNode));
|
||||
});
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceConflictingLexicallyDeclaredNames(otherNames, createError) {
|
||||
this.lexicallyDeclaredNames.forEachEntry((nodes, bindingName) => {
|
||||
if (otherNames.has(bindingName)) {
|
||||
nodes.forEach(conflictingNode => {
|
||||
this.addError(createError(conflictingNode));
|
||||
});
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
observeFunctionDeclaration() {
|
||||
this.observeVarBoundary();
|
||||
addEach(this.functionDeclarationNames, this.boundNames);
|
||||
this.boundNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
functionDeclarationNamesAreLexical() {
|
||||
addEach(this.lexicallyDeclaredNames, this.functionDeclarationNames);
|
||||
this.functionDeclarationNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
observeVarDeclaration() {
|
||||
addEach(this.varDeclaredNames, this.boundNames);
|
||||
this.boundNames = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
recordForOfVars() {
|
||||
this.varDeclaredNames.forEach(bindingIdentifier => {
|
||||
this.forOfVarDeclaredNames.push(bindingIdentifier);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
observeVarBoundary() {
|
||||
this.lexicallyDeclaredNames = new MultiMap;
|
||||
this.functionDeclarationNames = new MultiMap;
|
||||
this.varDeclaredNames = new MultiMap;
|
||||
this.forOfVarDeclaredNames = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
exportName(name, node) {
|
||||
this.exportedNames.set(name, node);
|
||||
return this;
|
||||
}
|
||||
|
||||
exportDeclaredNames() {
|
||||
addEach(this.exportedNames, this.lexicallyDeclaredNames, this.varDeclaredNames);
|
||||
addEach(this.exportedBindings, this.lexicallyDeclaredNames, this.varDeclaredNames);
|
||||
return this;
|
||||
}
|
||||
|
||||
exportBinding(name, node) {
|
||||
this.exportedBindings.set(name, node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearExportedBindings() {
|
||||
this.exportedBindings = new MultiMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
observeYieldExpression(node) {
|
||||
this.yieldExpressions.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearYieldExpressions() {
|
||||
this.yieldExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
observeAwaitExpression(node) {
|
||||
this.awaitExpressions.push(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
clearAwaitExpressions() {
|
||||
this.awaitExpressions = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
addError(e) {
|
||||
this.errors.push(e);
|
||||
return this;
|
||||
}
|
||||
|
||||
addStrictError(e) {
|
||||
this.strictErrors.push(e);
|
||||
return this;
|
||||
}
|
||||
|
||||
enforceStrictErrors() {
|
||||
[].push.apply(this.errors, this.strictErrors);
|
||||
this.strictErrors = [];
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// MONOID IMPLEMENTATION
|
||||
|
||||
static empty() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
concat(s) {
|
||||
if (this === identity) return s;
|
||||
if (s === identity) return this;
|
||||
[].push.apply(this.errors, s.errors);
|
||||
[].push.apply(this.strictErrors, s.strictErrors);
|
||||
[].push.apply(this.usedLabelNames, s.usedLabelNames);
|
||||
[].push.apply(this.freeBreakStatements, s.freeBreakStatements);
|
||||
[].push.apply(this.freeContinueStatements, s.freeContinueStatements);
|
||||
[].push.apply(this.freeLabeledBreakStatements, s.freeLabeledBreakStatements);
|
||||
[].push.apply(this.freeLabeledContinueStatements, s.freeLabeledContinueStatements);
|
||||
[].push.apply(this.newTargetExpressions, s.newTargetExpressions);
|
||||
addEach(this.boundNames, s.boundNames);
|
||||
addEach(this.lexicallyDeclaredNames, s.lexicallyDeclaredNames);
|
||||
addEach(this.functionDeclarationNames, s.functionDeclarationNames);
|
||||
addEach(this.varDeclaredNames, s.varDeclaredNames);
|
||||
[].push.apply(this.forOfVarDeclaredNames, s.forOfVarDeclaredNames);
|
||||
addEach(this.exportedNames, s.exportedNames);
|
||||
addEach(this.exportedBindings, s.exportedBindings);
|
||||
[].push.apply(this.superCallExpressions, s.superCallExpressions);
|
||||
[].push.apply(this.superCallExpressionsInConstructorMethod, s.superCallExpressionsInConstructorMethod);
|
||||
[].push.apply(this.superPropertyExpressions, s.superPropertyExpressions);
|
||||
[].push.apply(this.yieldExpressions, s.yieldExpressions);
|
||||
[].push.apply(this.awaitExpressions, s.awaitExpressions);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
identity = new EarlyErrorState;
|
||||
Object.getOwnPropertyNames(EarlyErrorState.prototype).forEach(methodName => {
|
||||
if (methodName === 'constructor') return;
|
||||
Object.defineProperty(identity, methodName, {
|
||||
value() {
|
||||
return EarlyErrorState.prototype[methodName].apply(new EarlyErrorState, arguments);
|
||||
},
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
});
|
||||
|
||||
class EarlyError extends Error {
|
||||
constructor(node, message) {
|
||||
super(message);
|
||||
this.node = node;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
EarlyErrorState,
|
||||
EarlyError,
|
||||
};
|
|
@ -0,0 +1,767 @@
|
|||
/**
|
||||
* Copyright 2014 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { reduce, MonoidalReducer } = require('shift-reducer');
|
||||
const { isStrictModeReservedWord } = require('./utils');
|
||||
const { ErrorMessages } = require('./errors');
|
||||
|
||||
const { EarlyErrorState, EarlyError } = require('./early-error-state');
|
||||
|
||||
function isStrictFunctionBody({ directives }) {
|
||||
return directives.some(directive => directive.rawValue === 'use strict');
|
||||
}
|
||||
|
||||
function isLabelledFunction(node) {
|
||||
return node.type === 'LabeledStatement' &&
|
||||
(node.body.type === 'FunctionDeclaration' || isLabelledFunction(node.body));
|
||||
}
|
||||
|
||||
function isIterationStatement(node) {
|
||||
switch (node.type) {
|
||||
case 'LabeledStatement':
|
||||
return isIterationStatement(node.body);
|
||||
case 'DoWhileStatement':
|
||||
case 'ForInStatement':
|
||||
case 'ForOfStatement':
|
||||
case 'ForStatement':
|
||||
case 'WhileStatement':
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSpecialMethod(methodDefinition) {
|
||||
if (methodDefinition.name.type !== 'StaticPropertyName' || methodDefinition.name.value !== 'constructor') {
|
||||
return false;
|
||||
}
|
||||
switch (methodDefinition.type) {
|
||||
case 'Getter':
|
||||
case 'Setter':
|
||||
return true;
|
||||
case 'Method':
|
||||
return methodDefinition.isGenerator || methodDefinition.isAsync;
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
throw new Error('not reached');
|
||||
}
|
||||
|
||||
|
||||
function enforceDuplicateConstructorMethods(node, s) {
|
||||
let ctors = node.elements.filter(e =>
|
||||
!e.isStatic &&
|
||||
e.method.type === 'Method' &&
|
||||
!e.method.isGenerator &&
|
||||
e.method.name.type === 'StaticPropertyName' &&
|
||||
e.method.name.value === 'constructor'
|
||||
);
|
||||
if (ctors.length > 1) {
|
||||
ctors.slice(1).forEach(ctor => {
|
||||
s = s.addError(new EarlyError(ctor, 'Duplicate constructor method in class'));
|
||||
});
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
const SUPERCALL_ERROR = node => new EarlyError(node, ErrorMessages.ILLEGAL_SUPER_CALL);
|
||||
const SUPERPROPERTY_ERROR = node => new EarlyError(node, 'Member access on super must be in a method');
|
||||
const DUPLICATE_BINDING = node => new EarlyError(node, `Duplicate binding ${JSON.stringify(node.name)}`);
|
||||
const FREE_CONTINUE = node => new EarlyError(node, 'Continue statement must be nested within an iteration statement');
|
||||
const UNBOUND_CONTINUE = node => new EarlyError(node, `Continue statement must be nested within an iteration statement with label ${JSON.stringify(node.label)}`);
|
||||
const FREE_BREAK = node => new EarlyError(node, 'Break statement must be nested within an iteration statement or a switch statement');
|
||||
const UNBOUND_BREAK = node => new EarlyError(node, `Break statement must be nested within a statement with label ${JSON.stringify(node.label)}`);
|
||||
|
||||
class EarlyErrorChecker extends MonoidalReducer {
|
||||
constructor() {
|
||||
super(EarlyErrorState);
|
||||
}
|
||||
|
||||
reduceAssignmentExpression() {
|
||||
return super.reduceAssignmentExpression(...arguments).clearBoundNames();
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
let s = this.identity;
|
||||
if (node.name === 'eval' || node.name === 'arguments' || isStrictModeReservedWord(node.name)) {
|
||||
s = s.addStrictError(new EarlyError(node, `The identifier ${JSON.stringify(node.name)} must not be in binding position in strict mode`));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
let isSimpleParameterList = node.params.rest == null && node.params.items.every(i => i.type === 'BindingIdentifier');
|
||||
params = params.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
if (node.body.type === 'FunctionBody') {
|
||||
body = body.enforceConflictingLexicallyDeclaredNames(params.lexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
params = params.enforceStrictErrors();
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
}
|
||||
params.yieldExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Arrow parameters must not contain yield expressions'));
|
||||
});
|
||||
params.awaitExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Arrow parameters must not contain await expressions'));
|
||||
});
|
||||
let s = super.reduceArrowExpression(node, { params, body });
|
||||
if (!isSimpleParameterList && node.body.type === 'FunctionBody' && isStrictFunctionBody(node.body)) {
|
||||
s = s.addError(new EarlyError(node, 'Functions with non-simple parameter lists may not contain a "use strict" directive'));
|
||||
}
|
||||
s = s.clearYieldExpressions();
|
||||
s = s.clearAwaitExpressions();
|
||||
s = s.observeVarBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return expression.observeAwaitExpression(node);
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
let s = this.identity;
|
||||
if (node.name === 'eval' || node.name === 'arguments' || isStrictModeReservedWord(node.name)) {
|
||||
s = s.addStrictError(new EarlyError(node, `The identifier ${JSON.stringify(node.name)} must not be in binding position in strict mode`));
|
||||
}
|
||||
s = s.bindName(node.name, node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceBlock() {
|
||||
let s = super.reduceBlock(...arguments);
|
||||
s = s.functionDeclarationNamesAreLexical();
|
||||
s = s.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
s = s.enforceConflictingLexicallyDeclaredNames(s.varDeclaredNames, DUPLICATE_BINDING);
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
let s = super.reduceBreakStatement(...arguments);
|
||||
s = node.label == null
|
||||
? s.addFreeBreakStatement(node)
|
||||
: s.addFreeLabeledBreakStatement(node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceCallExpression(node) {
|
||||
let s = super.reduceCallExpression(...arguments);
|
||||
if (node.callee.type === 'Super') {
|
||||
s = s.observeSuperCallExpression(node);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
if (binding != null) {
|
||||
binding = binding.observeLexicalDeclaration();
|
||||
binding = binding.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
binding = binding.enforceConflictingLexicallyDeclaredNames(body.previousLexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
}
|
||||
let s = super.reduceCatchClause(node, { binding, body });
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
let s = name.enforceStrictErrors();
|
||||
let sElements = this.append(...elements);
|
||||
sElements = sElements.enforceStrictErrors();
|
||||
if (node.super != null) {
|
||||
_super = _super.enforceStrictErrors();
|
||||
s = this.append(s, _super);
|
||||
sElements = sElements.clearSuperCallExpressionsInConstructorMethod();
|
||||
}
|
||||
s = this.append(s, sElements);
|
||||
s = enforceDuplicateConstructorMethods(node, s);
|
||||
s = s.observeLexicalDeclaration();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceClassElement(node) {
|
||||
let s = super.reduceClassElement(...arguments);
|
||||
if (!node.isStatic && isSpecialMethod(node.method)) {
|
||||
s = s.addError(new EarlyError(node, ErrorMessages.ILLEGAL_CONSTRUCTORS));
|
||||
}
|
||||
if (node.isStatic && node.method.name.type === 'StaticPropertyName' && node.method.name.value === 'prototype') {
|
||||
s = s.addError(new EarlyError(node, 'Static class methods cannot be named "prototype"'));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
let s = node.name == null ? this.identity : name.enforceStrictErrors();
|
||||
let sElements = this.append(...elements);
|
||||
sElements = sElements.enforceStrictErrors();
|
||||
if (node.super != null) {
|
||||
_super = _super.enforceStrictErrors();
|
||||
s = this.append(s, _super);
|
||||
sElements = sElements.clearSuperCallExpressionsInConstructorMethod();
|
||||
}
|
||||
s = this.append(s, sElements);
|
||||
s = enforceDuplicateConstructorMethods(node, s);
|
||||
s = s.clearBoundNames();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression() {
|
||||
return super.reduceCompoundAssignmentExpression(...arguments).clearBoundNames();
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node) {
|
||||
let s = super.reduceComputedMemberExpression(...arguments);
|
||||
if (node.object.type === 'Super') {
|
||||
s = s.observeSuperPropertyExpression(node);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
let s = super.reduceContinueStatement(...arguments);
|
||||
s = node.label == null
|
||||
? s.addFreeContinueStatement(node)
|
||||
: s.addFreeLabeledContinueStatement(node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node) {
|
||||
let s = super.reduceDoWhileStatement(...arguments);
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a do-while statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements();
|
||||
s = s.clearFreeBreakStatements();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceExport() {
|
||||
let s = super.reduceExport(...arguments);
|
||||
s = s.functionDeclarationNamesAreLexical();
|
||||
s = s.exportDeclaredNames();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceExportFrom() {
|
||||
let s = super.reduceExportFrom(...arguments);
|
||||
s = s.clearExportedBindings();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
let s = super.reduceExportFromSpecifier(...arguments);
|
||||
s = s.exportName(node.exportedName || node.name, node);
|
||||
s = s.exportBinding(node.name, node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node) {
|
||||
let s = super.reduceExportLocalSpecifier(...arguments);
|
||||
s = s.exportName(node.exportedName || node.name.name, node);
|
||||
s = s.exportBinding(node.name.name, node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceExportDefault(node) {
|
||||
let s = super.reduceExportDefault(...arguments);
|
||||
s = s.functionDeclarationNamesAreLexical();
|
||||
s = s.exportName('default', node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceFormalParameters() {
|
||||
let s = super.reduceFormalParameters(...arguments);
|
||||
s = s.observeLexicalDeclaration();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
if (init != null) {
|
||||
init = init.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
init = init.enforceConflictingLexicallyDeclaredNames(body.varDeclaredNames, DUPLICATE_BINDING);
|
||||
}
|
||||
let s = super.reduceForStatement(node, { init, test, update, body });
|
||||
if (node.init != null && node.init.type === 'VariableDeclaration' && node.init.kind === 'const') {
|
||||
node.init.declarators.forEach(declarator => {
|
||||
if (declarator.init == null) {
|
||||
s = s.addError(new EarlyError(declarator, 'Constant lexical declarations must have an initialiser'));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a for statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements();
|
||||
s = s.clearFreeBreakStatements();
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
left = left.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
left = left.enforceConflictingLexicallyDeclaredNames(body.varDeclaredNames, DUPLICATE_BINDING);
|
||||
let s = super.reduceForInStatement(node, { left, right, body });
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a for-in statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements();
|
||||
s = s.clearFreeBreakStatements();
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
left = left.recordForOfVars();
|
||||
left = left.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
left = left.enforceConflictingLexicallyDeclaredNames(body.varDeclaredNames, DUPLICATE_BINDING);
|
||||
let s = super.reduceForOfStatement(node, { left, right, body });
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a for-of statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements();
|
||||
s = s.clearFreeBreakStatements();
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
left = left.recordForOfVars();
|
||||
left = left.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
left = left.enforceConflictingLexicallyDeclaredNames(body.varDeclaredNames, DUPLICATE_BINDING);
|
||||
let s = super.reduceForOfStatement(node, { left, right, body });
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a for-await statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements();
|
||||
s = s.clearFreeBreakStatements();
|
||||
s = s.observeLexicalBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceFunctionBody(node) {
|
||||
let s = super.reduceFunctionBody(...arguments);
|
||||
s = s.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
s = s.enforceConflictingLexicallyDeclaredNames(s.varDeclaredNames, DUPLICATE_BINDING);
|
||||
s = s.enforceFreeContinueStatementErrors(FREE_CONTINUE);
|
||||
s = s.enforceFreeLabeledContinueStatementErrors(UNBOUND_CONTINUE);
|
||||
s = s.enforceFreeBreakStatementErrors(FREE_BREAK);
|
||||
s = s.enforceFreeLabeledBreakStatementErrors(UNBOUND_BREAK);
|
||||
s = s.clearUsedLabelNames();
|
||||
s = s.clearYieldExpressions();
|
||||
s = s.clearAwaitExpressions();
|
||||
if (isStrictFunctionBody(node)) {
|
||||
s = s.enforceStrictErrors();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
let isSimpleParameterList = node.params.rest == null && node.params.items.every(i => i.type === 'BindingIdentifier');
|
||||
let addError = !isSimpleParameterList || node.isGenerator ? 'addError' : 'addStrictError';
|
||||
params.lexicallyDeclaredNames.forEachEntry(nodes => {
|
||||
if (nodes.length > 1) {
|
||||
nodes.slice(1).forEach(dupeNode => {
|
||||
params = params[addError](DUPLICATE_BINDING(dupeNode));
|
||||
});
|
||||
}
|
||||
});
|
||||
body = body.enforceConflictingLexicallyDeclaredNames(params.lexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
body = body.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
body = body.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
params = params.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
params = params.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
if (node.isGenerator) {
|
||||
params.yieldExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Generator parameters must not contain yield expressions'));
|
||||
});
|
||||
}
|
||||
if (node.isAsync) {
|
||||
params.awaitExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Async function parameters must not contain await expressions'));
|
||||
});
|
||||
}
|
||||
params = params.clearNewTargetExpressions();
|
||||
body = body.clearNewTargetExpressions();
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
params = params.enforceStrictErrors();
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
let s = super.reduceFunctionDeclaration(node, { name, params, body });
|
||||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) {
|
||||
s = s.addError(new EarlyError(node, 'Functions with non-simple parameter lists may not contain a "use strict" directive'));
|
||||
}
|
||||
s = s.clearYieldExpressions();
|
||||
s = s.clearAwaitExpressions();
|
||||
s = s.observeFunctionDeclaration();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
let isSimpleParameterList = node.params.rest == null && node.params.items.every(i => i.type === 'BindingIdentifier');
|
||||
let addError = !isSimpleParameterList || node.isGenerator ? 'addError' : 'addStrictError';
|
||||
params.lexicallyDeclaredNames.forEachEntry((nodes, bindingName) => {
|
||||
if (nodes.length > 1) {
|
||||
nodes.slice(1).forEach(dupeNode => {
|
||||
params = params[addError](new EarlyError(dupeNode, `Duplicate binding ${JSON.stringify(bindingName)}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
body = body.enforceConflictingLexicallyDeclaredNames(params.lexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
body = body.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
body = body.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
params = params.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
params = params.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
if (node.isGenerator) {
|
||||
params.yieldExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Generator parameters must not contain yield expressions'));
|
||||
});
|
||||
}
|
||||
if (node.isAsync) {
|
||||
params.awaitExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Async function parameters must not contain await expressions'));
|
||||
});
|
||||
}
|
||||
params = params.clearNewTargetExpressions();
|
||||
body = body.clearNewTargetExpressions();
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
params = params.enforceStrictErrors();
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
let s = super.reduceFunctionExpression(node, { name, params, body });
|
||||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) {
|
||||
s = s.addError(new EarlyError(node, 'Functions with non-simple parameter lists may not contain a "use strict" directive'));
|
||||
}
|
||||
s = s.clearBoundNames();
|
||||
s = s.clearYieldExpressions();
|
||||
s = s.clearAwaitExpressions();
|
||||
s = s.observeVarBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
body = body.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
body = body.clearSuperPropertyExpressions();
|
||||
body = body.clearNewTargetExpressions();
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
let s = super.reduceGetter(node, { name, body });
|
||||
s = s.observeVarBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
let s = this.identity;
|
||||
if (isStrictModeReservedWord(node.name)) {
|
||||
s = s.addStrictError(new EarlyError(node, `The identifier ${JSON.stringify(node.name)} must not be in expression position in strict mode`));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
if (isLabelledFunction(node.consequent)) {
|
||||
consequent = consequent.addError(new EarlyError(node.consequent, 'The consequent of an if statement must not be a labeled function declaration'));
|
||||
}
|
||||
if (node.alternate != null && isLabelledFunction(node.alternate)) {
|
||||
alternate = alternate.addError(new EarlyError(node.alternate, 'The alternate of an if statement must not be a labeled function declaration'));
|
||||
}
|
||||
if (node.consequent.type === 'FunctionDeclaration') {
|
||||
consequent = consequent.addStrictError(new EarlyError(node.consequent, 'FunctionDeclarations in IfStatements are disallowed in strict mode'));
|
||||
consequent = consequent.observeLexicalBoundary();
|
||||
}
|
||||
if (node.alternate != null && node.alternate.type === 'FunctionDeclaration') {
|
||||
alternate = alternate.addStrictError(new EarlyError(node.alternate, 'FunctionDeclarations in IfStatements are disallowed in strict mode'));
|
||||
alternate = alternate.observeLexicalBoundary();
|
||||
}
|
||||
return super.reduceIfStatement(node, { test, consequent, alternate });
|
||||
}
|
||||
|
||||
reduceImport() {
|
||||
let s = super.reduceImport(...arguments);
|
||||
s = s.observeLexicalDeclaration();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceImportNamespace() {
|
||||
let s = super.reduceImportNamespace(...arguments);
|
||||
s = s.observeLexicalDeclaration();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node) {
|
||||
let s = super.reduceLabeledStatement(...arguments);
|
||||
if (node.label === 'yield' || isStrictModeReservedWord(node.label)) {
|
||||
s = s.addStrictError(new EarlyError(node, `The identifier ${JSON.stringify(node.label)} must not be in label position in strict mode`));
|
||||
}
|
||||
if (s.usedLabelNames.indexOf(node.label) >= 0) {
|
||||
s = s.addError(new EarlyError(node, `Label ${JSON.stringify(node.label)} has already been declared`));
|
||||
}
|
||||
if (node.body.type === 'FunctionDeclaration') {
|
||||
s = s.addStrictError(new EarlyError(node, 'Labeled FunctionDeclarations are disallowed in strict mode'));
|
||||
}
|
||||
s = isIterationStatement(node.body)
|
||||
? s.observeIterationLabel(node.label)
|
||||
: s.observeNonIterationLabel(node.label);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression() {
|
||||
let s = this.identity;
|
||||
// NOTE: the RegExp pattern acceptor is disabled until we have more confidence in its correctness (more tests)
|
||||
// if (!PatternAcceptor.test(node.pattern, node.flags.indexOf("u") >= 0)) {
|
||||
// s = s.addError(new EarlyError(node, "Invalid regular expression pattern"));
|
||||
// }
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
let isSimpleParameterList = node.params.rest == null && node.params.items.every(i => i.type === 'BindingIdentifier');
|
||||
params = params.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
body = body.enforceConflictingLexicallyDeclaredNames(params.lexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
if (node.name.type === 'StaticPropertyName' && node.name.value === 'constructor') {
|
||||
body = body.observeConstructorMethod();
|
||||
params = params.observeConstructorMethod();
|
||||
} else {
|
||||
body = body.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
params = params.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
}
|
||||
if (node.isGenerator) {
|
||||
params.yieldExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Generator parameters must not contain yield expressions'));
|
||||
});
|
||||
}
|
||||
if (node.isAsync) {
|
||||
params.awaitExpressions.forEach(n => {
|
||||
params = params.addError(new EarlyError(n, 'Async function parameters must not contain await expressions'));
|
||||
});
|
||||
}
|
||||
body = body.clearSuperPropertyExpressions();
|
||||
params = params.clearSuperPropertyExpressions();
|
||||
params = params.clearNewTargetExpressions();
|
||||
body = body.clearNewTargetExpressions();
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
params = params.enforceStrictErrors();
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
let s = super.reduceMethod(node, { name, params, body });
|
||||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) {
|
||||
s = s.addError(new EarlyError(node, 'Functions with non-simple parameter lists may not contain a "use strict" directive'));
|
||||
}
|
||||
s = s.clearYieldExpressions();
|
||||
s = s.clearAwaitExpressions();
|
||||
s = s.observeVarBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceModule() {
|
||||
let s = super.reduceModule(...arguments);
|
||||
s = s.functionDeclarationNamesAreLexical();
|
||||
s = s.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
s = s.enforceConflictingLexicallyDeclaredNames(s.varDeclaredNames, DUPLICATE_BINDING);
|
||||
s.exportedNames.forEachEntry((nodes, bindingName) => {
|
||||
if (nodes.length > 1) {
|
||||
nodes.slice(1).forEach(dupeNode => {
|
||||
s = s.addError(new EarlyError(dupeNode, `Duplicate export ${JSON.stringify(bindingName)}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
s.exportedBindings.forEachEntry((nodes, bindingName) => {
|
||||
if (!s.lexicallyDeclaredNames.has(bindingName) && !s.varDeclaredNames.has(bindingName)) {
|
||||
nodes.forEach(undeclaredNode => {
|
||||
s = s.addError(new EarlyError(undeclaredNode, `Exported binding ${JSON.stringify(bindingName)} is not declared`));
|
||||
});
|
||||
}
|
||||
});
|
||||
s.newTargetExpressions.forEach(node => {
|
||||
s = s.addError(new EarlyError(node, 'new.target must be within function (but not arrow expression) code'));
|
||||
});
|
||||
s = s.enforceFreeContinueStatementErrors(FREE_CONTINUE);
|
||||
s = s.enforceFreeLabeledContinueStatementErrors(UNBOUND_CONTINUE);
|
||||
s = s.enforceFreeBreakStatementErrors(FREE_BREAK);
|
||||
s = s.enforceFreeLabeledBreakStatementErrors(UNBOUND_BREAK);
|
||||
s = s.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
s = s.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
s = s.enforceStrictErrors();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return this.identity.observeNewTargetExpression(node);
|
||||
}
|
||||
|
||||
reduceObjectExpression(node) {
|
||||
let s = super.reduceObjectExpression(...arguments);
|
||||
s = s.enforceSuperCallExpressionsInConstructorMethod(SUPERCALL_ERROR);
|
||||
let protos = node.properties.filter(p => p.type === 'DataProperty' && p.name.type === 'StaticPropertyName' && p.name.value === '__proto__');
|
||||
protos.slice(1).forEach(n => {
|
||||
s = s.addError(new EarlyError(n, 'Duplicate __proto__ property in object literal not allowed'));
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceUpdateExpression() {
|
||||
let s = super.reduceUpdateExpression(...arguments);
|
||||
s = s.clearBoundNames();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node) {
|
||||
let s = super.reduceUnaryExpression(...arguments);
|
||||
if (node.operator === 'delete' && node.operand.type === 'IdentifierExpression') {
|
||||
s = s.addStrictError(new EarlyError(node, 'Identifier expressions must not be deleted in strict mode'));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceScript(node) {
|
||||
let s = super.reduceScript(...arguments);
|
||||
s = s.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
s = s.enforceConflictingLexicallyDeclaredNames(s.varDeclaredNames, DUPLICATE_BINDING);
|
||||
s.newTargetExpressions.forEach(n => {
|
||||
s = s.addError(new EarlyError(n, 'new.target must be within function (but not arrow expression) code'));
|
||||
});
|
||||
s = s.enforceFreeContinueStatementErrors(FREE_CONTINUE);
|
||||
s = s.enforceFreeLabeledContinueStatementErrors(UNBOUND_CONTINUE);
|
||||
s = s.enforceFreeBreakStatementErrors(FREE_BREAK);
|
||||
s = s.enforceFreeLabeledBreakStatementErrors(UNBOUND_BREAK);
|
||||
s = s.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
s = s.enforceSuperPropertyExpressions(SUPERPROPERTY_ERROR);
|
||||
if (isStrictFunctionBody(node)) {
|
||||
s = s.enforceStrictErrors();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
let isSimpleParameterList = node.param.type === 'BindingIdentifier';
|
||||
param = param.observeLexicalDeclaration();
|
||||
param = param.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
body = body.enforceConflictingLexicallyDeclaredNames(param.lexicallyDeclaredNames, DUPLICATE_BINDING);
|
||||
param = param.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
body = body.enforceSuperCallExpressions(SUPERCALL_ERROR);
|
||||
param = param.clearSuperPropertyExpressions();
|
||||
body = body.clearSuperPropertyExpressions();
|
||||
param = param.clearNewTargetExpressions();
|
||||
body = body.clearNewTargetExpressions();
|
||||
if (isStrictFunctionBody(node.body)) {
|
||||
param = param.enforceStrictErrors();
|
||||
body = body.enforceStrictErrors();
|
||||
}
|
||||
let s = super.reduceSetter(node, { name, param, body });
|
||||
if (!isSimpleParameterList && isStrictFunctionBody(node.body)) {
|
||||
s = s.addError(new EarlyError(node, 'Functions with non-simple parameter lists may not contain a "use strict" directive'));
|
||||
}
|
||||
s = s.observeVarBoundary();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node) {
|
||||
let s = super.reduceStaticMemberExpression(...arguments);
|
||||
if (node.object.type === 'Super') {
|
||||
s = s.observeSuperPropertyExpression(node);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
let sCases = this.append(...cases);
|
||||
sCases = sCases.functionDeclarationNamesAreLexical();
|
||||
sCases = sCases.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
sCases = sCases.enforceConflictingLexicallyDeclaredNames(sCases.varDeclaredNames, DUPLICATE_BINDING);
|
||||
sCases = sCases.observeLexicalBoundary();
|
||||
let s = this.append(discriminant, sCases);
|
||||
s = s.clearFreeBreakStatements();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
let sCases = this.append(defaultCase, ...preDefaultCases, ...postDefaultCases);
|
||||
sCases = sCases.functionDeclarationNamesAreLexical();
|
||||
sCases = sCases.enforceDuplicateLexicallyDeclaredNames(DUPLICATE_BINDING);
|
||||
sCases = sCases.enforceConflictingLexicallyDeclaredNames(sCases.varDeclaredNames, DUPLICATE_BINDING);
|
||||
sCases = sCases.observeLexicalBoundary();
|
||||
let s = this.append(discriminant, sCases);
|
||||
s = s.clearFreeBreakStatements();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node) {
|
||||
let s = super.reduceVariableDeclaration(...arguments);
|
||||
switch (node.kind) {
|
||||
case 'const':
|
||||
case 'let': {
|
||||
s = s.observeLexicalDeclaration();
|
||||
if (s.lexicallyDeclaredNames.has('let')) {
|
||||
s.lexicallyDeclaredNames.get('let').forEach(n => {
|
||||
s = s.addError(new EarlyError(n, 'Lexical declarations must not have a binding named "let"'));
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'var':
|
||||
s = s.observeVarDeclaration();
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node) {
|
||||
let s = super.reduceVariableDeclarationStatement(...arguments);
|
||||
if (node.declaration.kind === 'const') {
|
||||
node.declaration.declarators.forEach(declarator => {
|
||||
if (declarator.init == null) {
|
||||
s = s.addError(new EarlyError(declarator, 'Constant lexical declarations must have an initialiser'));
|
||||
}
|
||||
});
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceWhileStatement(node) {
|
||||
let s = super.reduceWhileStatement(...arguments);
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a while statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.clearFreeContinueStatements().clearFreeBreakStatements();
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceWithStatement(node) {
|
||||
let s = super.reduceWithStatement(...arguments);
|
||||
if (isLabelledFunction(node.body)) {
|
||||
s = s.addError(new EarlyError(node.body, 'The body of a with statement must not be a labeled function declaration'));
|
||||
}
|
||||
s = s.addStrictError(new EarlyError(node, 'Strict mode code must not include a with statement'));
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceYieldExpression(node) {
|
||||
let s = super.reduceYieldExpression(...arguments);
|
||||
s = s.observeYieldExpression(node);
|
||||
return s;
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node) {
|
||||
let s = super.reduceYieldGeneratorExpression(...arguments);
|
||||
s = s.observeYieldExpression(node);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
static check(node) {
|
||||
return reduce(new EarlyErrorChecker, node).errors;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { EarlyErrorChecker };
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Copyright 2014 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
ErrorMessages: {
|
||||
UNEXPECTED_TOKEN(id) {
|
||||
return `Unexpected token ${JSON.stringify(id)}`;
|
||||
},
|
||||
UNEXPECTED_ILLEGAL_TOKEN(id) {
|
||||
return `Unexpected ${JSON.stringify(id)}`;
|
||||
},
|
||||
UNEXPECTED_ESCAPED_KEYWORD: 'Unexpected escaped keyword',
|
||||
UNEXPECTED_NUMBER: 'Unexpected number',
|
||||
UNEXPECTED_STRING: 'Unexpected string',
|
||||
UNEXPECTED_IDENTIFIER: 'Unexpected identifier',
|
||||
UNEXPECTED_RESERVED_WORD: 'Unexpected reserved word',
|
||||
UNEXPECTED_TEMPLATE: 'Unexpected template',
|
||||
UNEXPECTED_EOS: 'Unexpected end of input',
|
||||
UNEXPECTED_LINE_TERMINATOR: 'Unexpected line terminator',
|
||||
UNEXPECTED_COMMA_AFTER_REST: 'Unexpected comma after rest',
|
||||
UNEXPECTED_REST_PARAMETERS_INITIALIZATION: 'Rest parameter may not have a default initializer',
|
||||
NEWLINE_AFTER_THROW: 'Illegal newline after throw',
|
||||
UNTERMINATED_REGEXP: 'Invalid regular expression: missing /',
|
||||
INVALID_LAST_REST_PARAMETER: 'Rest parameter must be last formal parameter',
|
||||
INVALID_REST_PARAMETERS_INITIALIZATION: 'Rest parameter may not have a default initializer',
|
||||
INVALID_REGEXP_FLAGS: 'Invalid regular expression flags',
|
||||
INVALID_REGEX: 'Invalid regular expression',
|
||||
INVALID_LHS_IN_ASSIGNMENT: 'Invalid left-hand side in assignment',
|
||||
INVALID_LHS_IN_BINDING: 'Invalid left-hand side in binding', // todo collapse messages?
|
||||
INVALID_LHS_IN_FOR_IN: 'Invalid left-hand side in for-in',
|
||||
INVALID_LHS_IN_FOR_OF: 'Invalid left-hand side in for-of',
|
||||
INVALID_LHS_IN_FOR_AWAIT: 'Invalid left-hand side in for-await',
|
||||
INVALID_UPDATE_OPERAND: 'Increment/decrement target must be an identifier or member expression',
|
||||
INVALID_EXPONENTIATION_LHS: 'Unary expressions as the left operand of an exponentation expression ' +
|
||||
'must be disambiguated with parentheses',
|
||||
MULTIPLE_DEFAULTS_IN_SWITCH: 'More than one default clause in switch statement',
|
||||
NO_CATCH_OR_FINALLY: 'Missing catch or finally after try',
|
||||
ILLEGAL_RETURN: 'Illegal return statement',
|
||||
ILLEGAL_ARROW_FUNCTION_PARAMS: 'Illegal arrow function parameter list',
|
||||
INVALID_ASYNC_PARAMS: 'Async function parameters must not contain await expressions',
|
||||
INVALID_VAR_INIT_FOR_IN: 'Invalid variable declaration in for-in statement',
|
||||
INVALID_VAR_INIT_FOR_OF: 'Invalid variable declaration in for-of statement',
|
||||
INVALID_VAR_INIT_FOR_AWAIT: 'Invalid variable declaration in for-await statement',
|
||||
UNINITIALIZED_BINDINGPATTERN_IN_FOR_INIT: 'Binding pattern appears without initializer in for statement init',
|
||||
ILLEGAL_PROPERTY: 'Illegal property initializer',
|
||||
INVALID_ID_BINDING_STRICT_MODE(id) {
|
||||
return `The identifier ${JSON.stringify(id)} must not be in binding position in strict mode`;
|
||||
},
|
||||
INVALID_ID_IN_LABEL_STRICT_MODE(id) {
|
||||
return `The identifier ${JSON.stringify(id)} must not be in label position in strict mode`;
|
||||
},
|
||||
INVALID_ID_IN_EXPRESSION_STRICT_MODE(id) {
|
||||
return `The identifier ${JSON.stringify(id)} must not be in expression position in strict mode`;
|
||||
},
|
||||
INVALID_CALL_TO_SUPER: 'Calls to super must be in the "constructor" method of a class expression ' +
|
||||
'or class declaration that has a superclass',
|
||||
INVALID_DELETE_STRICT_MODE: 'Identifier expressions must not be deleted in strict mode',
|
||||
DUPLICATE_BINDING(id) {
|
||||
return `Duplicate binding ${JSON.stringify(id)}`;
|
||||
},
|
||||
ILLEGAL_ID_IN_LEXICAL_DECLARATION(id) {
|
||||
return `Lexical declarations must not have a binding named ${JSON.stringify(id)}`;
|
||||
},
|
||||
UNITIALIZED_CONST: 'Constant lexical declarations must have an initialiser',
|
||||
ILLEGAL_LABEL_IN_BODY(stmt) {
|
||||
return `The body of a ${stmt} statement must not be a labeled function declaration`;
|
||||
},
|
||||
ILLEGEAL_LABEL_IN_IF: 'The consequent of an if statement must not be a labeled function declaration',
|
||||
ILLEGAL_LABEL_IN_ELSE: 'The alternate of an if statement must not be a labeled function declaration',
|
||||
ILLEGAL_CONTINUE_WITHOUT_ITERATION_WITH_ID(id) {
|
||||
return `Continue statement must be nested within an iteration statement with label ${JSON.stringify(id)}`;
|
||||
},
|
||||
ILLEGAL_CONTINUE_WITHOUT_ITERATION: 'Continue statement must be nested within an iteration statement',
|
||||
ILLEGAL_BREAK_WITHOUT_ITERATION_OR_SWITCH:
|
||||
'Break statement must be nested within an iteration statement or a switch statement',
|
||||
ILLEGAL_WITH_STRICT_MODE: 'Strict mode code must not include a with statement',
|
||||
ILLEGAL_ACCESS_SUPER_MEMBER: 'Member access on super must be in a method',
|
||||
ILLEGAL_SUPER_CALL: 'Calls to super must be in the "constructor" method of a class expression or class declaration that has a superclass',
|
||||
DUPLICATE_LABEL_DECLARATION(label) {
|
||||
return `Label ${JSON.stringify(label)} has already been declared`;
|
||||
},
|
||||
ILLEGAL_BREAK_WITHIN_LABEL(label) {
|
||||
return `Break statement must be nested within a statement with label ${JSON.stringify(label)}`;
|
||||
},
|
||||
ILLEGAL_YIELD_EXPRESSIONS(paramType) {
|
||||
return `${paramType} parameters must not contain yield expressions`;
|
||||
},
|
||||
ILLEGAL_YIELD_IDENTIFIER: '"yield" may not be used as an identifier in this context',
|
||||
ILLEGAL_AWAIT_IDENTIFIER: '"await" may not be used as an identifier in this context',
|
||||
DUPLICATE_CONSTRUCTOR: 'Duplicate constructor method in class',
|
||||
ILLEGAL_CONSTRUCTORS: 'Constructors cannot be async, generators, getters or setters',
|
||||
ILLEGAL_STATIC_CLASS_NAME: 'Static class methods cannot be named "prototype"',
|
||||
NEW_TARGET_ERROR: 'new.target must be within function (but not arrow expression) code',
|
||||
DUPLICATE_EXPORT(id) {
|
||||
return `Duplicate export ${JSON.stringify(id)}`;
|
||||
},
|
||||
UNDECLARED_BINDING(id) {
|
||||
return `Exported binding ${JSON.stringify(id)} is not declared`;
|
||||
},
|
||||
DUPLICATE_PROPTO_PROP: 'Duplicate __proto__ property in object literal not allowed',
|
||||
ILLEGAL_LABEL_FUNC_DECLARATION: 'Labeled FunctionDeclarations are disallowed in strict mode',
|
||||
ILLEGAL_FUNC_DECL_IF: 'FunctionDeclarations in IfStatements are disallowed in strict mode',
|
||||
ILLEGAL_USE_STRICT: 'Functions with non-simple parameter lists may not contain a "use strict" directive',
|
||||
ILLEGAL_EXPORTED_NAME: 'Names of variables used in an export specifier from the current module must be identifiers',
|
||||
NO_OCTALS_IN_TEMPLATES: 'Template literals may not contain octal escape sequences',
|
||||
NO_AWAIT_IN_ASYNC_PARAMS: 'Async arrow parameters may not contain "await"',
|
||||
},
|
||||
};
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* Copyright 2016 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { GenericParser } = require('./parser');
|
||||
const { JsError } = require('./tokenizer');
|
||||
const { EarlyErrorChecker } = require('./early-errors');
|
||||
const { isLineTerminator } = require('./utils');
|
||||
const { Tokenizer, TokenClass, TokenType } = require('./tokenizer');
|
||||
|
||||
class ParserWithLocation extends GenericParser {
|
||||
constructor(source) {
|
||||
super(source);
|
||||
this.locations = new WeakMap;
|
||||
this.comments = [];
|
||||
}
|
||||
|
||||
startNode() {
|
||||
return this.getLocation();
|
||||
}
|
||||
|
||||
finishNode(node, start) {
|
||||
if (node.type === 'Script' || node.type === 'Module') {
|
||||
this.locations.set(node, {
|
||||
start: { line: 1, column: 0, offset: 0 },
|
||||
end: this.getLocation(),
|
||||
});
|
||||
return node;
|
||||
}
|
||||
if (node.type === 'TemplateExpression') {
|
||||
// Adjust TemplateElements to not include surrounding backticks or braces
|
||||
for (let i = 0; i < node.elements.length; i += 2) {
|
||||
const endAdjustment = i < node.elements.length - 1 ? 2 : 1; // discard '${' or '`' respectively
|
||||
const element = node.elements[i];
|
||||
const location = this.locations.get(element);
|
||||
this.locations.set(element, {
|
||||
start: { line: location.start.line, column: location.start.column + 1, offset: location.start.offset + 1 }, // discard '}' or '`'
|
||||
end: { line: location.end.line, column: location.end.column - endAdjustment, offset: location.end.offset - endAdjustment },
|
||||
});
|
||||
}
|
||||
}
|
||||
this.locations.set(node, {
|
||||
start,
|
||||
end: this.getLastTokenEndLocation(),
|
||||
});
|
||||
return node;
|
||||
}
|
||||
|
||||
copyNode(src, dest) {
|
||||
this.locations.set(dest, this.locations.get(src)); // todo check undefined
|
||||
return dest;
|
||||
}
|
||||
|
||||
skipSingleLineComment(offset) {
|
||||
// We're actually extending the *tokenizer*, here.
|
||||
const start = {
|
||||
line: this.line + 1,
|
||||
column: this.index - this.lineStart,
|
||||
offset: this.index,
|
||||
};
|
||||
const c = this.source[this.index];
|
||||
const type = c === '/' ? 'SingleLine' : c === '<' ? 'HTMLOpen' : 'HTMLClose';
|
||||
|
||||
super.skipSingleLineComment(offset);
|
||||
|
||||
const end = {
|
||||
line: this.line + 1,
|
||||
column: this.index - this.lineStart,
|
||||
offset: this.index,
|
||||
};
|
||||
const trailingLineTerminatorCharacters = this.source[this.index - 2] === '\r' ? 2 : isLineTerminator(this.source.charCodeAt(this.index - 1)) ? 1 : 0;
|
||||
const text = this.source.substring(start.offset + offset, end.offset - trailingLineTerminatorCharacters);
|
||||
|
||||
this.comments.push({ text, type, start, end });
|
||||
}
|
||||
|
||||
skipMultiLineComment() {
|
||||
const start = {
|
||||
line: this.line + 1,
|
||||
column: this.index - this.lineStart,
|
||||
offset: this.index,
|
||||
};
|
||||
const type = 'MultiLine';
|
||||
|
||||
const retval = super.skipMultiLineComment();
|
||||
|
||||
const end = {
|
||||
line: this.line + 1,
|
||||
column: this.index - this.lineStart,
|
||||
offset: this.index,
|
||||
};
|
||||
const text = this.source.substring(start.offset + 2, end.offset - 2);
|
||||
|
||||
this.comments.push({ text, type, start, end });
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
function generateInterface(parsingFunctionName) {
|
||||
return function parse(code, { earlyErrors = true } = {}) {
|
||||
let parser = new GenericParser(code);
|
||||
let tree = parser[parsingFunctionName]();
|
||||
if (earlyErrors) {
|
||||
let errors = EarlyErrorChecker.check(tree);
|
||||
// for now, just throw the first error; we will handle multiple errors later
|
||||
if (errors.length > 0) {
|
||||
throw new JsError(0, 1, 0, errors[0].message);
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
};
|
||||
}
|
||||
|
||||
function generateInterfaceWithLocation(parsingFunctionName) {
|
||||
return function parse(code, { earlyErrors = true } = {}) {
|
||||
let parser = new ParserWithLocation(code);
|
||||
let tree = parser[parsingFunctionName]();
|
||||
if (earlyErrors) {
|
||||
let errors = EarlyErrorChecker.check(tree);
|
||||
// for now, just throw the first error; we will handle multiple errors later
|
||||
if (errors.length > 0) {
|
||||
let { node, message } = errors[0];
|
||||
let { offset, line, column } = parser.locations.get(node).start;
|
||||
throw new JsError(offset, line, column, message);
|
||||
}
|
||||
}
|
||||
return { tree, locations: parser.locations, comments: parser.comments };
|
||||
};
|
||||
}
|
||||
|
||||
const parseScript = generateInterface('parseScript');
|
||||
const parseModule = generateInterface('parseModule');
|
||||
const parseModuleWithLocation = generateInterfaceWithLocation('parseModule');
|
||||
const parseScriptWithLocation = generateInterfaceWithLocation('parseScript');
|
||||
|
||||
module.exports = {
|
||||
default: parseScript,
|
||||
parseScript,
|
||||
parseModule,
|
||||
parseModuleWithLocation,
|
||||
parseScriptWithLocation,
|
||||
EarlyErrorChecker,
|
||||
GenericParser,
|
||||
ParserWithLocation,
|
||||
Tokenizer,
|
||||
TokenClass,
|
||||
TokenType,
|
||||
};
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* Copyright 2017 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { whitespaceArray, whitespaceBool, idStartLargeRegex, idStartBool, idContinueLargeRegex, idContinueBool } = require('./unicode');
|
||||
|
||||
|
||||
const strictReservedWords = [
|
||||
'null',
|
||||
'true',
|
||||
'false',
|
||||
|
||||
'implements',
|
||||
'interface',
|
||||
'package',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'static',
|
||||
'let',
|
||||
|
||||
'if',
|
||||
'in',
|
||||
'do',
|
||||
'var',
|
||||
'for',
|
||||
'new',
|
||||
'try',
|
||||
'this',
|
||||
'else',
|
||||
'case',
|
||||
'void',
|
||||
'with',
|
||||
'enum',
|
||||
'while',
|
||||
'break',
|
||||
'catch',
|
||||
'throw',
|
||||
'const',
|
||||
'yield',
|
||||
'class',
|
||||
'super',
|
||||
'return',
|
||||
'typeof',
|
||||
'delete',
|
||||
'switch',
|
||||
'export',
|
||||
'import',
|
||||
'default',
|
||||
'finally',
|
||||
'extends',
|
||||
'function',
|
||||
'continue',
|
||||
'debugger',
|
||||
'instanceof',
|
||||
];
|
||||
|
||||
exports.isStrictModeReservedWord = id => {
|
||||
return strictReservedWords.indexOf(id) !== -1;
|
||||
};
|
||||
|
||||
exports.isWhiteSpace = ch => {
|
||||
return ch < 128 ? whitespaceBool[ch] : ch === 0xA0 || ch > 0x167F && whitespaceArray.indexOf(ch) !== -1;
|
||||
};
|
||||
|
||||
exports.isLineTerminator = ch => {
|
||||
return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
|
||||
};
|
||||
|
||||
exports.isIdentifierStart = ch => {
|
||||
return ch < 128 ? idStartBool[ch] : idStartLargeRegex.test(String.fromCodePoint(ch));
|
||||
};
|
||||
|
||||
exports.isIdentifierPart = ch => {
|
||||
return ch < 128 ? idContinueBool[ch] : idContinueLargeRegex.test(String.fromCodePoint(ch));
|
||||
};
|
||||
|
||||
exports.isDecimalDigit = ch => {
|
||||
return ch >= 48 && ch <= 57;
|
||||
};
|
||||
|
||||
exports.getHexValue = rune => {
|
||||
if (rune >= '0' && rune <= '9') {
|
||||
return rune.charCodeAt(0) - 48;
|
||||
}
|
||||
if (rune >= 'a' && rune <= 'f') {
|
||||
return rune.charCodeAt(0) - 87;
|
||||
}
|
||||
if (rune >= 'A' && rune <= 'F') {
|
||||
return rune.charCodeAt(0) - 55;
|
||||
}
|
||||
return -1;
|
||||
};
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,60 @@
|
|||
Shift Reducer
|
||||
=============
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This module provides several reducers and related tooling for [Shift format](https://github.com/shapesecurity/shift-spec) ASTs.
|
||||
|
||||
|
||||
## Status
|
||||
|
||||
[Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install shift-reducer
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
See [examples](./examples).
|
||||
|
||||
|
||||
### Fantasy Land
|
||||
|
||||
![Fantasy Land logo](https://github.com/fantasyland/fantasy-land/raw/master/logo.png "Fantasy Land")
|
||||
|
||||
`MonoidalReducer` is compatible with [Fantasy Land](https://github.com/fantasyland/fantasy-land) Monoids.
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
* Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
|
||||
* Fork this repo, and clone the forked repo.
|
||||
* Install dependencies with `npm install`.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Create a feature branch. Make your changes. Add tests.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
|
||||
* Open a Pull Request on Github.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2014 Shape Security, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
extends: '../.eslintrc.js',
|
||||
rules: {
|
||||
'no-unused-vars': 'off',
|
||||
'max-len': 'off',
|
||||
'no-extra-parens': 'off',
|
||||
}
|
||||
}
|
|
@ -0,0 +1,418 @@
|
|||
// Generated by generate-adapt.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = (fn, reducer) => ({
|
||||
__proto__: reducer,
|
||||
|
||||
reduceArrayAssignmentTarget(node, data) {
|
||||
return fn(super.reduceArrayAssignmentTarget(node, data), node);
|
||||
},
|
||||
|
||||
reduceArrayBinding(node, data) {
|
||||
return fn(super.reduceArrayBinding(node, data), node);
|
||||
},
|
||||
|
||||
reduceArrayExpression(node, data) {
|
||||
return fn(super.reduceArrayExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceArrowExpression(node, data) {
|
||||
return fn(super.reduceArrowExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceAssignmentExpression(node, data) {
|
||||
return fn(super.reduceAssignmentExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceAssignmentTargetIdentifier(node, data) {
|
||||
return fn(super.reduceAssignmentTargetIdentifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, data) {
|
||||
return fn(super.reduceAssignmentTargetPropertyIdentifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, data) {
|
||||
return fn(super.reduceAssignmentTargetPropertyProperty(node, data), node);
|
||||
},
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, data) {
|
||||
return fn(super.reduceAssignmentTargetWithDefault(node, data), node);
|
||||
},
|
||||
|
||||
reduceAwaitExpression(node, data) {
|
||||
return fn(super.reduceAwaitExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceBinaryExpression(node, data) {
|
||||
return fn(super.reduceBinaryExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceBindingIdentifier(node, data) {
|
||||
return fn(super.reduceBindingIdentifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceBindingPropertyIdentifier(node, data) {
|
||||
return fn(super.reduceBindingPropertyIdentifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceBindingPropertyProperty(node, data) {
|
||||
return fn(super.reduceBindingPropertyProperty(node, data), node);
|
||||
},
|
||||
|
||||
reduceBindingWithDefault(node, data) {
|
||||
return fn(super.reduceBindingWithDefault(node, data), node);
|
||||
},
|
||||
|
||||
reduceBlock(node, data) {
|
||||
return fn(super.reduceBlock(node, data), node);
|
||||
},
|
||||
|
||||
reduceBlockStatement(node, data) {
|
||||
return fn(super.reduceBlockStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceBreakStatement(node, data) {
|
||||
return fn(super.reduceBreakStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceCallExpression(node, data) {
|
||||
return fn(super.reduceCallExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceCatchClause(node, data) {
|
||||
return fn(super.reduceCatchClause(node, data), node);
|
||||
},
|
||||
|
||||
reduceClassDeclaration(node, data) {
|
||||
return fn(super.reduceClassDeclaration(node, data), node);
|
||||
},
|
||||
|
||||
reduceClassElement(node, data) {
|
||||
return fn(super.reduceClassElement(node, data), node);
|
||||
},
|
||||
|
||||
reduceClassExpression(node, data) {
|
||||
return fn(super.reduceClassExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceCompoundAssignmentExpression(node, data) {
|
||||
return fn(super.reduceCompoundAssignmentExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, data) {
|
||||
return fn(super.reduceComputedMemberAssignmentTarget(node, data), node);
|
||||
},
|
||||
|
||||
reduceComputedMemberExpression(node, data) {
|
||||
return fn(super.reduceComputedMemberExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceComputedPropertyName(node, data) {
|
||||
return fn(super.reduceComputedPropertyName(node, data), node);
|
||||
},
|
||||
|
||||
reduceConditionalExpression(node, data) {
|
||||
return fn(super.reduceConditionalExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceContinueStatement(node, data) {
|
||||
return fn(super.reduceContinueStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceDataProperty(node, data) {
|
||||
return fn(super.reduceDataProperty(node, data), node);
|
||||
},
|
||||
|
||||
reduceDebuggerStatement(node, data) {
|
||||
return fn(super.reduceDebuggerStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceDirective(node, data) {
|
||||
return fn(super.reduceDirective(node, data), node);
|
||||
},
|
||||
|
||||
reduceDoWhileStatement(node, data) {
|
||||
return fn(super.reduceDoWhileStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceEmptyStatement(node, data) {
|
||||
return fn(super.reduceEmptyStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceExport(node, data) {
|
||||
return fn(super.reduceExport(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportAllFrom(node, data) {
|
||||
return fn(super.reduceExportAllFrom(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportDefault(node, data) {
|
||||
return fn(super.reduceExportDefault(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportFrom(node, data) {
|
||||
return fn(super.reduceExportFrom(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportFromSpecifier(node, data) {
|
||||
return fn(super.reduceExportFromSpecifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportLocalSpecifier(node, data) {
|
||||
return fn(super.reduceExportLocalSpecifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceExportLocals(node, data) {
|
||||
return fn(super.reduceExportLocals(node, data), node);
|
||||
},
|
||||
|
||||
reduceExpressionStatement(node, data) {
|
||||
return fn(super.reduceExpressionStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceForAwaitStatement(node, data) {
|
||||
return fn(super.reduceForAwaitStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceForInStatement(node, data) {
|
||||
return fn(super.reduceForInStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceForOfStatement(node, data) {
|
||||
return fn(super.reduceForOfStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceForStatement(node, data) {
|
||||
return fn(super.reduceForStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceFormalParameters(node, data) {
|
||||
return fn(super.reduceFormalParameters(node, data), node);
|
||||
},
|
||||
|
||||
reduceFunctionBody(node, data) {
|
||||
return fn(super.reduceFunctionBody(node, data), node);
|
||||
},
|
||||
|
||||
reduceFunctionDeclaration(node, data) {
|
||||
return fn(super.reduceFunctionDeclaration(node, data), node);
|
||||
},
|
||||
|
||||
reduceFunctionExpression(node, data) {
|
||||
return fn(super.reduceFunctionExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceGetter(node, data) {
|
||||
return fn(super.reduceGetter(node, data), node);
|
||||
},
|
||||
|
||||
reduceIdentifierExpression(node, data) {
|
||||
return fn(super.reduceIdentifierExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceIfStatement(node, data) {
|
||||
return fn(super.reduceIfStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceImport(node, data) {
|
||||
return fn(super.reduceImport(node, data), node);
|
||||
},
|
||||
|
||||
reduceImportNamespace(node, data) {
|
||||
return fn(super.reduceImportNamespace(node, data), node);
|
||||
},
|
||||
|
||||
reduceImportSpecifier(node, data) {
|
||||
return fn(super.reduceImportSpecifier(node, data), node);
|
||||
},
|
||||
|
||||
reduceLabeledStatement(node, data) {
|
||||
return fn(super.reduceLabeledStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralBooleanExpression(node, data) {
|
||||
return fn(super.reduceLiteralBooleanExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralInfinityExpression(node, data) {
|
||||
return fn(super.reduceLiteralInfinityExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralNullExpression(node, data) {
|
||||
return fn(super.reduceLiteralNullExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralNumericExpression(node, data) {
|
||||
return fn(super.reduceLiteralNumericExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralRegExpExpression(node, data) {
|
||||
return fn(super.reduceLiteralRegExpExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceLiteralStringExpression(node, data) {
|
||||
return fn(super.reduceLiteralStringExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceMethod(node, data) {
|
||||
return fn(super.reduceMethod(node, data), node);
|
||||
},
|
||||
|
||||
reduceModule(node, data) {
|
||||
return fn(super.reduceModule(node, data), node);
|
||||
},
|
||||
|
||||
reduceNewExpression(node, data) {
|
||||
return fn(super.reduceNewExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceNewTargetExpression(node, data) {
|
||||
return fn(super.reduceNewTargetExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceObjectAssignmentTarget(node, data) {
|
||||
return fn(super.reduceObjectAssignmentTarget(node, data), node);
|
||||
},
|
||||
|
||||
reduceObjectBinding(node, data) {
|
||||
return fn(super.reduceObjectBinding(node, data), node);
|
||||
},
|
||||
|
||||
reduceObjectExpression(node, data) {
|
||||
return fn(super.reduceObjectExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceReturnStatement(node, data) {
|
||||
return fn(super.reduceReturnStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceScript(node, data) {
|
||||
return fn(super.reduceScript(node, data), node);
|
||||
},
|
||||
|
||||
reduceSetter(node, data) {
|
||||
return fn(super.reduceSetter(node, data), node);
|
||||
},
|
||||
|
||||
reduceShorthandProperty(node, data) {
|
||||
return fn(super.reduceShorthandProperty(node, data), node);
|
||||
},
|
||||
|
||||
reduceSpreadElement(node, data) {
|
||||
return fn(super.reduceSpreadElement(node, data), node);
|
||||
},
|
||||
|
||||
reduceSpreadProperty(node, data) {
|
||||
return fn(super.reduceSpreadProperty(node, data), node);
|
||||
},
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, data) {
|
||||
return fn(super.reduceStaticMemberAssignmentTarget(node, data), node);
|
||||
},
|
||||
|
||||
reduceStaticMemberExpression(node, data) {
|
||||
return fn(super.reduceStaticMemberExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceStaticPropertyName(node, data) {
|
||||
return fn(super.reduceStaticPropertyName(node, data), node);
|
||||
},
|
||||
|
||||
reduceSuper(node, data) {
|
||||
return fn(super.reduceSuper(node, data), node);
|
||||
},
|
||||
|
||||
reduceSwitchCase(node, data) {
|
||||
return fn(super.reduceSwitchCase(node, data), node);
|
||||
},
|
||||
|
||||
reduceSwitchDefault(node, data) {
|
||||
return fn(super.reduceSwitchDefault(node, data), node);
|
||||
},
|
||||
|
||||
reduceSwitchStatement(node, data) {
|
||||
return fn(super.reduceSwitchStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceSwitchStatementWithDefault(node, data) {
|
||||
return fn(super.reduceSwitchStatementWithDefault(node, data), node);
|
||||
},
|
||||
|
||||
reduceTemplateElement(node, data) {
|
||||
return fn(super.reduceTemplateElement(node, data), node);
|
||||
},
|
||||
|
||||
reduceTemplateExpression(node, data) {
|
||||
return fn(super.reduceTemplateExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceThisExpression(node, data) {
|
||||
return fn(super.reduceThisExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceThrowStatement(node, data) {
|
||||
return fn(super.reduceThrowStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceTryCatchStatement(node, data) {
|
||||
return fn(super.reduceTryCatchStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceTryFinallyStatement(node, data) {
|
||||
return fn(super.reduceTryFinallyStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceUnaryExpression(node, data) {
|
||||
return fn(super.reduceUnaryExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceUpdateExpression(node, data) {
|
||||
return fn(super.reduceUpdateExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceVariableDeclaration(node, data) {
|
||||
return fn(super.reduceVariableDeclaration(node, data), node);
|
||||
},
|
||||
|
||||
reduceVariableDeclarationStatement(node, data) {
|
||||
return fn(super.reduceVariableDeclarationStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceVariableDeclarator(node, data) {
|
||||
return fn(super.reduceVariableDeclarator(node, data), node);
|
||||
},
|
||||
|
||||
reduceWhileStatement(node, data) {
|
||||
return fn(super.reduceWhileStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceWithStatement(node, data) {
|
||||
return fn(super.reduceWithStatement(node, data), node);
|
||||
},
|
||||
|
||||
reduceYieldExpression(node, data) {
|
||||
return fn(super.reduceYieldExpression(node, data), node);
|
||||
},
|
||||
|
||||
reduceYieldGeneratorExpression(node, data) {
|
||||
return fn(super.reduceYieldGeneratorExpression(node, data), node);
|
||||
},
|
||||
});
|
|
@ -0,0 +1,416 @@
|
|||
// Generated by generate-clone-reducer.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = class CloneReducer {
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
return new Shift.ArrayAssignmentTarget({ elements, rest });
|
||||
}
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
return new Shift.ArrayBinding({ elements, rest });
|
||||
}
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
return new Shift.ArrayExpression({ elements });
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
return new Shift.ArrowExpression({ isAsync: node.isAsync, params, body });
|
||||
}
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
return new Shift.AssignmentExpression({ binding, expression });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return new Shift.AssignmentTargetIdentifier({ name: node.name });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
return new Shift.AssignmentTargetPropertyIdentifier({ binding, init });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
return new Shift.AssignmentTargetPropertyProperty({ name, binding });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
return new Shift.AssignmentTargetWithDefault({ binding, init });
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return new Shift.AwaitExpression({ expression });
|
||||
}
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
return new Shift.BinaryExpression({ left, operator: node.operator, right });
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return new Shift.BindingIdentifier({ name: node.name });
|
||||
}
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
return new Shift.BindingPropertyIdentifier({ binding, init });
|
||||
}
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
return new Shift.BindingPropertyProperty({ name, binding });
|
||||
}
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
return new Shift.BindingWithDefault({ binding, init });
|
||||
}
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
return new Shift.Block({ statements });
|
||||
}
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
return new Shift.BlockStatement({ block });
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return new Shift.BreakStatement({ label: node.label });
|
||||
}
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
return new Shift.CallExpression({ callee, arguments: _arguments });
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
return new Shift.CatchClause({ binding, body });
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
return new Shift.ClassDeclaration({ name, super: _super, elements });
|
||||
}
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
return new Shift.ClassElement({ isStatic: node.isStatic, method });
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
return new Shift.ClassExpression({ name, super: _super, elements });
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
return new Shift.CompoundAssignmentExpression({ binding, operator: node.operator, expression });
|
||||
}
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
return new Shift.ComputedMemberAssignmentTarget({ object, expression });
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
return new Shift.ComputedMemberExpression({ object, expression });
|
||||
}
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
return new Shift.ComputedPropertyName({ expression });
|
||||
}
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
return new Shift.ConditionalExpression({ test, consequent, alternate });
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return new Shift.ContinueStatement({ label: node.label });
|
||||
}
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
return new Shift.DataProperty({ name, expression });
|
||||
}
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return new Shift.DebuggerStatement;
|
||||
}
|
||||
|
||||
reduceDirective(node) {
|
||||
return new Shift.Directive({ rawValue: node.rawValue });
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
return new Shift.DoWhileStatement({ body, test });
|
||||
}
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return new Shift.EmptyStatement;
|
||||
}
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
return new Shift.Export({ declaration });
|
||||
}
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return new Shift.ExportAllFrom({ moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
return new Shift.ExportDefault({ body });
|
||||
}
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
return new Shift.ExportFrom({ namedExports, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return new Shift.ExportFromSpecifier({ name: node.name, exportedName: node.exportedName });
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
return new Shift.ExportLocalSpecifier({ name, exportedName: node.exportedName });
|
||||
}
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
return new Shift.ExportLocals({ namedExports });
|
||||
}
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
return new Shift.ExpressionStatement({ expression });
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
return new Shift.ForAwaitStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
return new Shift.ForInStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
return new Shift.ForOfStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
return new Shift.ForStatement({ init, test, update, body });
|
||||
}
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
return new Shift.FormalParameters({ items, rest });
|
||||
}
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
return new Shift.FunctionBody({ directives, statements });
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
return new Shift.FunctionDeclaration({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
return new Shift.FunctionExpression({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
return new Shift.Getter({ name, body });
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return new Shift.IdentifierExpression({ name: node.name });
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
return new Shift.IfStatement({ test, consequent, alternate });
|
||||
}
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
return new Shift.Import({ defaultBinding, namedImports, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
return new Shift.ImportNamespace({ defaultBinding, namespaceBinding, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
return new Shift.ImportSpecifier({ name: node.name, binding });
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
return new Shift.LabeledStatement({ label: node.label, body });
|
||||
}
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return new Shift.LiteralBooleanExpression({ value: node.value });
|
||||
}
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return new Shift.LiteralInfinityExpression;
|
||||
}
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return new Shift.LiteralNullExpression;
|
||||
}
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return new Shift.LiteralNumericExpression({ value: node.value });
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return new Shift.LiteralRegExpExpression({ pattern: node.pattern, global: node.global, ignoreCase: node.ignoreCase, multiLine: node.multiLine, dotAll: node.dotAll, unicode: node.unicode, sticky: node.sticky });
|
||||
}
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return new Shift.LiteralStringExpression({ value: node.value });
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
return new Shift.Method({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
return new Shift.Module({ directives, items });
|
||||
}
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
return new Shift.NewExpression({ callee, arguments: _arguments });
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return new Shift.NewTargetExpression;
|
||||
}
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
return new Shift.ObjectAssignmentTarget({ properties, rest });
|
||||
}
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
return new Shift.ObjectBinding({ properties, rest });
|
||||
}
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
return new Shift.ObjectExpression({ properties });
|
||||
}
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
return new Shift.ReturnStatement({ expression });
|
||||
}
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
return new Shift.Script({ directives, statements });
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
return new Shift.Setter({ name, param, body });
|
||||
}
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
return new Shift.ShorthandProperty({ name });
|
||||
}
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
return new Shift.SpreadElement({ expression });
|
||||
}
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
return new Shift.SpreadProperty({ expression });
|
||||
}
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
return new Shift.StaticMemberAssignmentTarget({ object, property: node.property });
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
return new Shift.StaticMemberExpression({ object, property: node.property });
|
||||
}
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return new Shift.StaticPropertyName({ value: node.value });
|
||||
}
|
||||
|
||||
reduceSuper(node) {
|
||||
return new Shift.Super;
|
||||
}
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
return new Shift.SwitchCase({ test, consequent });
|
||||
}
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
return new Shift.SwitchDefault({ consequent });
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
return new Shift.SwitchStatement({ discriminant, cases });
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
return new Shift.SwitchStatementWithDefault({ discriminant, preDefaultCases, defaultCase, postDefaultCases });
|
||||
}
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return new Shift.TemplateElement({ rawValue: node.rawValue });
|
||||
}
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
return new Shift.TemplateExpression({ tag, elements });
|
||||
}
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return new Shift.ThisExpression;
|
||||
}
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
return new Shift.ThrowStatement({ expression });
|
||||
}
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
return new Shift.TryCatchStatement({ body, catchClause });
|
||||
}
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
return new Shift.TryFinallyStatement({ body, catchClause, finalizer });
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
return new Shift.UnaryExpression({ operator: node.operator, operand });
|
||||
}
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
return new Shift.UpdateExpression({ isPrefix: node.isPrefix, operator: node.operator, operand });
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
return new Shift.VariableDeclaration({ kind: node.kind, declarators });
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
return new Shift.VariableDeclarationStatement({ declaration });
|
||||
}
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
return new Shift.VariableDeclarator({ binding, init });
|
||||
}
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
return new Shift.WhileStatement({ test, body });
|
||||
}
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
return new Shift.WithStatement({ object, body });
|
||||
}
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
return new Shift.YieldExpression({ expression });
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
return new Shift.YieldGeneratorExpression({ expression });
|
||||
}
|
||||
};
|
|
@ -0,0 +1,418 @@
|
|||
// Generated by generate-director.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const director = {
|
||||
ArrayAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceArrayAssignmentTarget(node, { elements: node.elements.map(v => v && this[v.type](reducer, v)), rest: node.rest && this[node.rest.type](reducer, node.rest) });
|
||||
},
|
||||
|
||||
ArrayBinding(reducer, node) {
|
||||
return reducer.reduceArrayBinding(node, { elements: node.elements.map(v => v && this[v.type](reducer, v)), rest: node.rest && this[node.rest.type](reducer, node.rest) });
|
||||
},
|
||||
|
||||
ArrayExpression(reducer, node) {
|
||||
return reducer.reduceArrayExpression(node, { elements: node.elements.map(v => v && this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
ArrowExpression(reducer, node) {
|
||||
return reducer.reduceArrowExpression(node, { params: this.FormalParameters(reducer, node.params), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
AssignmentExpression(reducer, node) {
|
||||
return reducer.reduceAssignmentExpression(node, { binding: this[node.binding.type](reducer, node.binding), expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
AssignmentTargetIdentifier(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetIdentifier(node);
|
||||
},
|
||||
|
||||
AssignmentTargetPropertyIdentifier(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetPropertyIdentifier(node, { binding: this.AssignmentTargetIdentifier(reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) });
|
||||
},
|
||||
|
||||
AssignmentTargetPropertyProperty(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetPropertyProperty(node, { name: this[node.name.type](reducer, node.name), binding: this[node.binding.type](reducer, node.binding) });
|
||||
},
|
||||
|
||||
AssignmentTargetWithDefault(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetWithDefault(node, { binding: this[node.binding.type](reducer, node.binding), init: this[node.init.type](reducer, node.init) });
|
||||
},
|
||||
|
||||
AwaitExpression(reducer, node) {
|
||||
return reducer.reduceAwaitExpression(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
BinaryExpression(reducer, node) {
|
||||
return reducer.reduceBinaryExpression(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right) });
|
||||
},
|
||||
|
||||
BindingIdentifier(reducer, node) {
|
||||
return reducer.reduceBindingIdentifier(node);
|
||||
},
|
||||
|
||||
BindingPropertyIdentifier(reducer, node) {
|
||||
return reducer.reduceBindingPropertyIdentifier(node, { binding: this.BindingIdentifier(reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) });
|
||||
},
|
||||
|
||||
BindingPropertyProperty(reducer, node) {
|
||||
return reducer.reduceBindingPropertyProperty(node, { name: this[node.name.type](reducer, node.name), binding: this[node.binding.type](reducer, node.binding) });
|
||||
},
|
||||
|
||||
BindingWithDefault(reducer, node) {
|
||||
return reducer.reduceBindingWithDefault(node, { binding: this[node.binding.type](reducer, node.binding), init: this[node.init.type](reducer, node.init) });
|
||||
},
|
||||
|
||||
Block(reducer, node) {
|
||||
return reducer.reduceBlock(node, { statements: node.statements.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
BlockStatement(reducer, node) {
|
||||
return reducer.reduceBlockStatement(node, { block: this.Block(reducer, node.block) });
|
||||
},
|
||||
|
||||
BreakStatement(reducer, node) {
|
||||
return reducer.reduceBreakStatement(node);
|
||||
},
|
||||
|
||||
CallExpression(reducer, node) {
|
||||
return reducer.reduceCallExpression(node, { callee: this[node.callee.type](reducer, node.callee), arguments: node.arguments.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
CatchClause(reducer, node) {
|
||||
return reducer.reduceCatchClause(node, { binding: node.binding && this[node.binding.type](reducer, node.binding), body: this.Block(reducer, node.body) });
|
||||
},
|
||||
|
||||
ClassDeclaration(reducer, node) {
|
||||
return reducer.reduceClassDeclaration(node, { name: this.BindingIdentifier(reducer, node.name), super: node.super && this[node.super.type](reducer, node.super), elements: node.elements.map(v => this.ClassElement(reducer, v)) });
|
||||
},
|
||||
|
||||
ClassElement(reducer, node) {
|
||||
return reducer.reduceClassElement(node, { method: this[node.method.type](reducer, node.method) });
|
||||
},
|
||||
|
||||
ClassExpression(reducer, node) {
|
||||
return reducer.reduceClassExpression(node, { name: node.name && this.BindingIdentifier(reducer, node.name), super: node.super && this[node.super.type](reducer, node.super), elements: node.elements.map(v => this.ClassElement(reducer, v)) });
|
||||
},
|
||||
|
||||
CompoundAssignmentExpression(reducer, node) {
|
||||
return reducer.reduceCompoundAssignmentExpression(node, { binding: this[node.binding.type](reducer, node.binding), expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
ComputedMemberAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceComputedMemberAssignmentTarget(node, { object: this[node.object.type](reducer, node.object), expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
ComputedMemberExpression(reducer, node) {
|
||||
return reducer.reduceComputedMemberExpression(node, { object: this[node.object.type](reducer, node.object), expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
ComputedPropertyName(reducer, node) {
|
||||
return reducer.reduceComputedPropertyName(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
ConditionalExpression(reducer, node) {
|
||||
return reducer.reduceConditionalExpression(node, { test: this[node.test.type](reducer, node.test), consequent: this[node.consequent.type](reducer, node.consequent), alternate: this[node.alternate.type](reducer, node.alternate) });
|
||||
},
|
||||
|
||||
ContinueStatement(reducer, node) {
|
||||
return reducer.reduceContinueStatement(node);
|
||||
},
|
||||
|
||||
DataProperty(reducer, node) {
|
||||
return reducer.reduceDataProperty(node, { name: this[node.name.type](reducer, node.name), expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
DebuggerStatement(reducer, node) {
|
||||
return reducer.reduceDebuggerStatement(node);
|
||||
},
|
||||
|
||||
Directive(reducer, node) {
|
||||
return reducer.reduceDirective(node);
|
||||
},
|
||||
|
||||
DoWhileStatement(reducer, node) {
|
||||
return reducer.reduceDoWhileStatement(node, { body: this[node.body.type](reducer, node.body), test: this[node.test.type](reducer, node.test) });
|
||||
},
|
||||
|
||||
EmptyStatement(reducer, node) {
|
||||
return reducer.reduceEmptyStatement(node);
|
||||
},
|
||||
|
||||
Export(reducer, node) {
|
||||
return reducer.reduceExport(node, { declaration: this[node.declaration.type](reducer, node.declaration) });
|
||||
},
|
||||
|
||||
ExportAllFrom(reducer, node) {
|
||||
return reducer.reduceExportAllFrom(node);
|
||||
},
|
||||
|
||||
ExportDefault(reducer, node) {
|
||||
return reducer.reduceExportDefault(node, { body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
ExportFrom(reducer, node) {
|
||||
return reducer.reduceExportFrom(node, { namedExports: node.namedExports.map(v => this.ExportFromSpecifier(reducer, v)) });
|
||||
},
|
||||
|
||||
ExportFromSpecifier(reducer, node) {
|
||||
return reducer.reduceExportFromSpecifier(node);
|
||||
},
|
||||
|
||||
ExportLocalSpecifier(reducer, node) {
|
||||
return reducer.reduceExportLocalSpecifier(node, { name: this.IdentifierExpression(reducer, node.name) });
|
||||
},
|
||||
|
||||
ExportLocals(reducer, node) {
|
||||
return reducer.reduceExportLocals(node, { namedExports: node.namedExports.map(v => this.ExportLocalSpecifier(reducer, v)) });
|
||||
},
|
||||
|
||||
ExpressionStatement(reducer, node) {
|
||||
return reducer.reduceExpressionStatement(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
ForAwaitStatement(reducer, node) {
|
||||
return reducer.reduceForAwaitStatement(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
ForInStatement(reducer, node) {
|
||||
return reducer.reduceForInStatement(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
ForOfStatement(reducer, node) {
|
||||
return reducer.reduceForOfStatement(node, { left: this[node.left.type](reducer, node.left), right: this[node.right.type](reducer, node.right), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
ForStatement(reducer, node) {
|
||||
return reducer.reduceForStatement(node, { init: node.init && this[node.init.type](reducer, node.init), test: node.test && this[node.test.type](reducer, node.test), update: node.update && this[node.update.type](reducer, node.update), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
FormalParameters(reducer, node) {
|
||||
return reducer.reduceFormalParameters(node, { items: node.items.map(v => this[v.type](reducer, v)), rest: node.rest && this[node.rest.type](reducer, node.rest) });
|
||||
},
|
||||
|
||||
FunctionBody(reducer, node) {
|
||||
return reducer.reduceFunctionBody(node, { directives: node.directives.map(v => this.Directive(reducer, v)), statements: node.statements.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
FunctionDeclaration(reducer, node) {
|
||||
return reducer.reduceFunctionDeclaration(node, { name: this.BindingIdentifier(reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) });
|
||||
},
|
||||
|
||||
FunctionExpression(reducer, node) {
|
||||
return reducer.reduceFunctionExpression(node, { name: node.name && this.BindingIdentifier(reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) });
|
||||
},
|
||||
|
||||
Getter(reducer, node) {
|
||||
return reducer.reduceGetter(node, { name: this[node.name.type](reducer, node.name), body: this.FunctionBody(reducer, node.body) });
|
||||
},
|
||||
|
||||
IdentifierExpression(reducer, node) {
|
||||
return reducer.reduceIdentifierExpression(node);
|
||||
},
|
||||
|
||||
IfStatement(reducer, node) {
|
||||
return reducer.reduceIfStatement(node, { test: this[node.test.type](reducer, node.test), consequent: this[node.consequent.type](reducer, node.consequent), alternate: node.alternate && this[node.alternate.type](reducer, node.alternate) });
|
||||
},
|
||||
|
||||
Import(reducer, node) {
|
||||
return reducer.reduceImport(node, { defaultBinding: node.defaultBinding && this.BindingIdentifier(reducer, node.defaultBinding), namedImports: node.namedImports.map(v => this.ImportSpecifier(reducer, v)) });
|
||||
},
|
||||
|
||||
ImportNamespace(reducer, node) {
|
||||
return reducer.reduceImportNamespace(node, { defaultBinding: node.defaultBinding && this.BindingIdentifier(reducer, node.defaultBinding), namespaceBinding: this.BindingIdentifier(reducer, node.namespaceBinding) });
|
||||
},
|
||||
|
||||
ImportSpecifier(reducer, node) {
|
||||
return reducer.reduceImportSpecifier(node, { binding: this.BindingIdentifier(reducer, node.binding) });
|
||||
},
|
||||
|
||||
LabeledStatement(reducer, node) {
|
||||
return reducer.reduceLabeledStatement(node, { body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
LiteralBooleanExpression(reducer, node) {
|
||||
return reducer.reduceLiteralBooleanExpression(node);
|
||||
},
|
||||
|
||||
LiteralInfinityExpression(reducer, node) {
|
||||
return reducer.reduceLiteralInfinityExpression(node);
|
||||
},
|
||||
|
||||
LiteralNullExpression(reducer, node) {
|
||||
return reducer.reduceLiteralNullExpression(node);
|
||||
},
|
||||
|
||||
LiteralNumericExpression(reducer, node) {
|
||||
return reducer.reduceLiteralNumericExpression(node);
|
||||
},
|
||||
|
||||
LiteralRegExpExpression(reducer, node) {
|
||||
return reducer.reduceLiteralRegExpExpression(node);
|
||||
},
|
||||
|
||||
LiteralStringExpression(reducer, node) {
|
||||
return reducer.reduceLiteralStringExpression(node);
|
||||
},
|
||||
|
||||
Method(reducer, node) {
|
||||
return reducer.reduceMethod(node, { name: this[node.name.type](reducer, node.name), params: this.FormalParameters(reducer, node.params), body: this.FunctionBody(reducer, node.body) });
|
||||
},
|
||||
|
||||
Module(reducer, node) {
|
||||
return reducer.reduceModule(node, { directives: node.directives.map(v => this.Directive(reducer, v)), items: node.items.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
NewExpression(reducer, node) {
|
||||
return reducer.reduceNewExpression(node, { callee: this[node.callee.type](reducer, node.callee), arguments: node.arguments.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
NewTargetExpression(reducer, node) {
|
||||
return reducer.reduceNewTargetExpression(node);
|
||||
},
|
||||
|
||||
ObjectAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceObjectAssignmentTarget(node, { properties: node.properties.map(v => this[v.type](reducer, v)), rest: node.rest && this[node.rest.type](reducer, node.rest) });
|
||||
},
|
||||
|
||||
ObjectBinding(reducer, node) {
|
||||
return reducer.reduceObjectBinding(node, { properties: node.properties.map(v => this[v.type](reducer, v)), rest: node.rest && this.BindingIdentifier(reducer, node.rest) });
|
||||
},
|
||||
|
||||
ObjectExpression(reducer, node) {
|
||||
return reducer.reduceObjectExpression(node, { properties: node.properties.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
ReturnStatement(reducer, node) {
|
||||
return reducer.reduceReturnStatement(node, { expression: node.expression && this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
Script(reducer, node) {
|
||||
return reducer.reduceScript(node, { directives: node.directives.map(v => this.Directive(reducer, v)), statements: node.statements.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
Setter(reducer, node) {
|
||||
return reducer.reduceSetter(node, { name: this[node.name.type](reducer, node.name), param: this[node.param.type](reducer, node.param), body: this.FunctionBody(reducer, node.body) });
|
||||
},
|
||||
|
||||
ShorthandProperty(reducer, node) {
|
||||
return reducer.reduceShorthandProperty(node, { name: this.IdentifierExpression(reducer, node.name) });
|
||||
},
|
||||
|
||||
SpreadElement(reducer, node) {
|
||||
return reducer.reduceSpreadElement(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
SpreadProperty(reducer, node) {
|
||||
return reducer.reduceSpreadProperty(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
StaticMemberAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceStaticMemberAssignmentTarget(node, { object: this[node.object.type](reducer, node.object) });
|
||||
},
|
||||
|
||||
StaticMemberExpression(reducer, node) {
|
||||
return reducer.reduceStaticMemberExpression(node, { object: this[node.object.type](reducer, node.object) });
|
||||
},
|
||||
|
||||
StaticPropertyName(reducer, node) {
|
||||
return reducer.reduceStaticPropertyName(node);
|
||||
},
|
||||
|
||||
Super(reducer, node) {
|
||||
return reducer.reduceSuper(node);
|
||||
},
|
||||
|
||||
SwitchCase(reducer, node) {
|
||||
return reducer.reduceSwitchCase(node, { test: this[node.test.type](reducer, node.test), consequent: node.consequent.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
SwitchDefault(reducer, node) {
|
||||
return reducer.reduceSwitchDefault(node, { consequent: node.consequent.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
SwitchStatement(reducer, node) {
|
||||
return reducer.reduceSwitchStatement(node, { discriminant: this[node.discriminant.type](reducer, node.discriminant), cases: node.cases.map(v => this.SwitchCase(reducer, v)) });
|
||||
},
|
||||
|
||||
SwitchStatementWithDefault(reducer, node) {
|
||||
return reducer.reduceSwitchStatementWithDefault(node, { discriminant: this[node.discriminant.type](reducer, node.discriminant), preDefaultCases: node.preDefaultCases.map(v => this.SwitchCase(reducer, v)), defaultCase: this.SwitchDefault(reducer, node.defaultCase), postDefaultCases: node.postDefaultCases.map(v => this.SwitchCase(reducer, v)) });
|
||||
},
|
||||
|
||||
TemplateElement(reducer, node) {
|
||||
return reducer.reduceTemplateElement(node);
|
||||
},
|
||||
|
||||
TemplateExpression(reducer, node) {
|
||||
return reducer.reduceTemplateExpression(node, { tag: node.tag && this[node.tag.type](reducer, node.tag), elements: node.elements.map(v => this[v.type](reducer, v)) });
|
||||
},
|
||||
|
||||
ThisExpression(reducer, node) {
|
||||
return reducer.reduceThisExpression(node);
|
||||
},
|
||||
|
||||
ThrowStatement(reducer, node) {
|
||||
return reducer.reduceThrowStatement(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
TryCatchStatement(reducer, node) {
|
||||
return reducer.reduceTryCatchStatement(node, { body: this.Block(reducer, node.body), catchClause: this.CatchClause(reducer, node.catchClause) });
|
||||
},
|
||||
|
||||
TryFinallyStatement(reducer, node) {
|
||||
return reducer.reduceTryFinallyStatement(node, { body: this.Block(reducer, node.body), catchClause: node.catchClause && this.CatchClause(reducer, node.catchClause), finalizer: this.Block(reducer, node.finalizer) });
|
||||
},
|
||||
|
||||
UnaryExpression(reducer, node) {
|
||||
return reducer.reduceUnaryExpression(node, { operand: this[node.operand.type](reducer, node.operand) });
|
||||
},
|
||||
|
||||
UpdateExpression(reducer, node) {
|
||||
return reducer.reduceUpdateExpression(node, { operand: this[node.operand.type](reducer, node.operand) });
|
||||
},
|
||||
|
||||
VariableDeclaration(reducer, node) {
|
||||
return reducer.reduceVariableDeclaration(node, { declarators: node.declarators.map(v => this.VariableDeclarator(reducer, v)) });
|
||||
},
|
||||
|
||||
VariableDeclarationStatement(reducer, node) {
|
||||
return reducer.reduceVariableDeclarationStatement(node, { declaration: this.VariableDeclaration(reducer, node.declaration) });
|
||||
},
|
||||
|
||||
VariableDeclarator(reducer, node) {
|
||||
return reducer.reduceVariableDeclarator(node, { binding: this[node.binding.type](reducer, node.binding), init: node.init && this[node.init.type](reducer, node.init) });
|
||||
},
|
||||
|
||||
WhileStatement(reducer, node) {
|
||||
return reducer.reduceWhileStatement(node, { test: this[node.test.type](reducer, node.test), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
WithStatement(reducer, node) {
|
||||
return reducer.reduceWithStatement(node, { object: this[node.object.type](reducer, node.object), body: this[node.body.type](reducer, node.body) });
|
||||
},
|
||||
|
||||
YieldExpression(reducer, node) {
|
||||
return reducer.reduceYieldExpression(node, { expression: node.expression && this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
|
||||
YieldGeneratorExpression(reducer, node) {
|
||||
return reducer.reduceYieldGeneratorExpression(node, { expression: this[node.expression.type](reducer, node.expression) });
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = function reduce(reducer, node) {
|
||||
return director[node.type](reducer, node);
|
||||
};
|
|
@ -0,0 +1,650 @@
|
|||
// Generated by generate-lazy-clone-reducer.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = class LazyCloneReducer {
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
if ((node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i])) && node.rest === rest) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ArrayAssignmentTarget({ elements, rest });
|
||||
}
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
if ((node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i])) && node.rest === rest) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ArrayBinding({ elements, rest });
|
||||
}
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
if ((node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ArrayExpression({ elements });
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
if (node.params === params && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ArrowExpression({ isAsync: node.isAsync, params, body });
|
||||
}
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
if (node.binding === binding && node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.AssignmentExpression({ binding, expression });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
if (node.binding === binding && node.init === init) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.AssignmentTargetPropertyIdentifier({ binding, init });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
if (node.name === name && node.binding === binding) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.AssignmentTargetPropertyProperty({ name, binding });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
if (node.binding === binding && node.init === init) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.AssignmentTargetWithDefault({ binding, init });
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.AwaitExpression({ expression });
|
||||
}
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
if (node.left === left && node.right === right) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.BinaryExpression({ left, operator: node.operator, right });
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
if (node.binding === binding && node.init === init) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.BindingPropertyIdentifier({ binding, init });
|
||||
}
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
if (node.name === name && node.binding === binding) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.BindingPropertyProperty({ name, binding });
|
||||
}
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
if (node.binding === binding && node.init === init) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.BindingWithDefault({ binding, init });
|
||||
}
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
if ((node.statements.length === statements.length && node.statements.every((v, i) => v === statements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Block({ statements });
|
||||
}
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
if (node.block === block) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.BlockStatement({ block });
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
if (node.callee === callee && (node.arguments.length === _arguments.length && node.arguments.every((v, i) => v === _arguments[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.CallExpression({ callee, arguments: _arguments });
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
if (node.binding === binding && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.CatchClause({ binding, body });
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
if (node.name === name && node.super === _super && (node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ClassDeclaration({ name, super: _super, elements });
|
||||
}
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
if (node.method === method) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ClassElement({ isStatic: node.isStatic, method });
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
if (node.name === name && node.super === _super && (node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ClassExpression({ name, super: _super, elements });
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
if (node.binding === binding && node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.CompoundAssignmentExpression({ binding, operator: node.operator, expression });
|
||||
}
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
if (node.object === object && node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ComputedMemberAssignmentTarget({ object, expression });
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
if (node.object === object && node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ComputedMemberExpression({ object, expression });
|
||||
}
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ComputedPropertyName({ expression });
|
||||
}
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
if (node.test === test && node.consequent === consequent && node.alternate === alternate) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ConditionalExpression({ test, consequent, alternate });
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
if (node.name === name && node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.DataProperty({ name, expression });
|
||||
}
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceDirective(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
if (node.body === body && node.test === test) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.DoWhileStatement({ body, test });
|
||||
}
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
if (node.declaration === declaration) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Export({ declaration });
|
||||
}
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
if (node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ExportDefault({ body });
|
||||
}
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
if ((node.namedExports.length === namedExports.length && node.namedExports.every((v, i) => v === namedExports[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ExportFrom({ namedExports, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
if (node.name === name) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ExportLocalSpecifier({ name, exportedName: node.exportedName });
|
||||
}
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
if ((node.namedExports.length === namedExports.length && node.namedExports.every((v, i) => v === namedExports[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ExportLocals({ namedExports });
|
||||
}
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ExpressionStatement({ expression });
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
if (node.left === left && node.right === right && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ForAwaitStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
if (node.left === left && node.right === right && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ForInStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
if (node.left === left && node.right === right && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ForOfStatement({ left, right, body });
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
if (node.init === init && node.test === test && node.update === update && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ForStatement({ init, test, update, body });
|
||||
}
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
if ((node.items.length === items.length && node.items.every((v, i) => v === items[i])) && node.rest === rest) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.FormalParameters({ items, rest });
|
||||
}
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
if ((node.directives.length === directives.length && node.directives.every((v, i) => v === directives[i])) && (node.statements.length === statements.length && node.statements.every((v, i) => v === statements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.FunctionBody({ directives, statements });
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
if (node.name === name && node.params === params && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.FunctionDeclaration({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
if (node.name === name && node.params === params && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.FunctionExpression({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
if (node.name === name && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Getter({ name, body });
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
if (node.test === test && node.consequent === consequent && node.alternate === alternate) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.IfStatement({ test, consequent, alternate });
|
||||
}
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
if (node.defaultBinding === defaultBinding && (node.namedImports.length === namedImports.length && node.namedImports.every((v, i) => v === namedImports[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Import({ defaultBinding, namedImports, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
if (node.defaultBinding === defaultBinding && node.namespaceBinding === namespaceBinding) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ImportNamespace({ defaultBinding, namespaceBinding, moduleSpecifier: node.moduleSpecifier });
|
||||
}
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
if (node.binding === binding) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ImportSpecifier({ name: node.name, binding });
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
if (node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.LabeledStatement({ label: node.label, body });
|
||||
}
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
if (node.name === name && node.params === params && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Method({ isAsync: node.isAsync, isGenerator: node.isGenerator, name, params, body });
|
||||
}
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
if ((node.directives.length === directives.length && node.directives.every((v, i) => v === directives[i])) && (node.items.length === items.length && node.items.every((v, i) => v === items[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Module({ directives, items });
|
||||
}
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
if (node.callee === callee && (node.arguments.length === _arguments.length && node.arguments.every((v, i) => v === _arguments[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.NewExpression({ callee, arguments: _arguments });
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
if ((node.properties.length === properties.length && node.properties.every((v, i) => v === properties[i])) && node.rest === rest) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ObjectAssignmentTarget({ properties, rest });
|
||||
}
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
if ((node.properties.length === properties.length && node.properties.every((v, i) => v === properties[i])) && node.rest === rest) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ObjectBinding({ properties, rest });
|
||||
}
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
if ((node.properties.length === properties.length && node.properties.every((v, i) => v === properties[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ObjectExpression({ properties });
|
||||
}
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ReturnStatement({ expression });
|
||||
}
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
if ((node.directives.length === directives.length && node.directives.every((v, i) => v === directives[i])) && (node.statements.length === statements.length && node.statements.every((v, i) => v === statements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Script({ directives, statements });
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
if (node.name === name && node.param === param && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.Setter({ name, param, body });
|
||||
}
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
if (node.name === name) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ShorthandProperty({ name });
|
||||
}
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SpreadElement({ expression });
|
||||
}
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SpreadProperty({ expression });
|
||||
}
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
if (node.object === object) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.StaticMemberAssignmentTarget({ object, property: node.property });
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
if (node.object === object) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.StaticMemberExpression({ object, property: node.property });
|
||||
}
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceSuper(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
if (node.test === test && (node.consequent.length === consequent.length && node.consequent.every((v, i) => v === consequent[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SwitchCase({ test, consequent });
|
||||
}
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
if ((node.consequent.length === consequent.length && node.consequent.every((v, i) => v === consequent[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SwitchDefault({ consequent });
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
if (node.discriminant === discriminant && (node.cases.length === cases.length && node.cases.every((v, i) => v === cases[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SwitchStatement({ discriminant, cases });
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
if (node.discriminant === discriminant && (node.preDefaultCases.length === preDefaultCases.length && node.preDefaultCases.every((v, i) => v === preDefaultCases[i])) && node.defaultCase === defaultCase && (node.postDefaultCases.length === postDefaultCases.length && node.postDefaultCases.every((v, i) => v === postDefaultCases[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.SwitchStatementWithDefault({ discriminant, preDefaultCases, defaultCase, postDefaultCases });
|
||||
}
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
if (node.tag === tag && (node.elements.length === elements.length && node.elements.every((v, i) => v === elements[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.TemplateExpression({ tag, elements });
|
||||
}
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.ThrowStatement({ expression });
|
||||
}
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
if (node.body === body && node.catchClause === catchClause) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.TryCatchStatement({ body, catchClause });
|
||||
}
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
if (node.body === body && node.catchClause === catchClause && node.finalizer === finalizer) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.TryFinallyStatement({ body, catchClause, finalizer });
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
if (node.operand === operand) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.UnaryExpression({ operator: node.operator, operand });
|
||||
}
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
if (node.operand === operand) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.UpdateExpression({ isPrefix: node.isPrefix, operator: node.operator, operand });
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
if ((node.declarators.length === declarators.length && node.declarators.every((v, i) => v === declarators[i]))) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.VariableDeclaration({ kind: node.kind, declarators });
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
if (node.declaration === declaration) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.VariableDeclarationStatement({ declaration });
|
||||
}
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
if (node.binding === binding && node.init === init) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.VariableDeclarator({ binding, init });
|
||||
}
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
if (node.test === test && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.WhileStatement({ test, body });
|
||||
}
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
if (node.object === object && node.body === body) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.WithStatement({ object, body });
|
||||
}
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.YieldExpression({ expression });
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
if (node.expression === expression) {
|
||||
return node;
|
||||
}
|
||||
return new Shift.YieldGeneratorExpression({ expression });
|
||||
}
|
||||
};
|
|
@ -0,0 +1,914 @@
|
|||
// Generated by generate-memoize.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = function memoize(reducer) {
|
||||
const cache = new WeakMap;
|
||||
return {
|
||||
reduceArrayAssignmentTarget(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceArrayAssignmentTarget(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceArrayBinding(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceArrayBinding(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceArrayExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceArrayExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceArrowExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceArrowExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAssignmentExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAssignmentExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAssignmentTargetIdentifier(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAssignmentTargetPropertyIdentifier(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAssignmentTargetPropertyProperty(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAssignmentTargetWithDefault(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceAwaitExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceAwaitExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBinaryExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBinaryExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBindingIdentifier(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBindingPropertyIdentifier(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBindingPropertyIdentifier(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBindingPropertyProperty(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBindingPropertyProperty(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBindingWithDefault(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBindingWithDefault(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBlock(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBlock(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBlockStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBlockStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceBreakStatement(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceCallExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceCallExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceCatchClause(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceCatchClause(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceClassDeclaration(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceClassDeclaration(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceClassElement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceClassElement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceClassExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceClassExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceCompoundAssignmentExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceCompoundAssignmentExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceComputedMemberAssignmentTarget(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceComputedMemberExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceComputedMemberExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceComputedPropertyName(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceComputedPropertyName(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceConditionalExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceConditionalExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceContinueStatement(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceDataProperty(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceDataProperty(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceDebuggerStatement(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceDirective(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceDirective(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceDoWhileStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceDoWhileStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceEmptyStatement(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExport(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExport(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportAllFrom(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportDefault(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportDefault(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportFrom(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportFrom(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportFromSpecifier(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportLocalSpecifier(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportLocalSpecifier(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExportLocals(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExportLocals(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceExpressionStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceExpressionStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceForAwaitStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceForAwaitStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceForInStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceForInStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceForOfStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceForOfStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceForStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceForStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceFormalParameters(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceFormalParameters(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceFunctionBody(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceFunctionBody(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceFunctionDeclaration(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceFunctionDeclaration(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceFunctionExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceFunctionExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceGetter(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceGetter(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceIdentifierExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceIfStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceIfStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceImport(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceImport(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceImportNamespace(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceImportNamespace(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceImportSpecifier(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceImportSpecifier(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLabeledStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLabeledStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralBooleanExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralInfinityExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralNullExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralNumericExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralRegExpExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceLiteralStringExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceMethod(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceMethod(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceModule(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceModule(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceNewExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceNewExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceNewTargetExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceObjectAssignmentTarget(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceObjectAssignmentTarget(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceObjectBinding(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceObjectBinding(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceObjectExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceObjectExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceReturnStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceReturnStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceScript(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceScript(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSetter(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSetter(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceShorthandProperty(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceShorthandProperty(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSpreadElement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSpreadElement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSpreadProperty(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSpreadProperty(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceStaticMemberAssignmentTarget(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceStaticMemberExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceStaticMemberExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceStaticPropertyName(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSuper(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSuper(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSwitchCase(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSwitchCase(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSwitchDefault(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSwitchDefault(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSwitchStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSwitchStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceSwitchStatementWithDefault(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceSwitchStatementWithDefault(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceTemplateElement(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceTemplateExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceTemplateExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceThisExpression(node) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceThisExpression(node);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceThrowStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceThrowStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceTryCatchStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceTryCatchStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceTryFinallyStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceTryFinallyStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceUnaryExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceUnaryExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceUpdateExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceUpdateExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceVariableDeclaration(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceVariableDeclaration(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceVariableDeclarationStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceVariableDeclarationStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceVariableDeclarator(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceVariableDeclarator(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceWhileStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceWhileStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceWithStatement(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceWithStatement(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceYieldExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceYieldExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
|
||||
reduceYieldGeneratorExpression(node, arg) {
|
||||
if (cache.has(node)) {
|
||||
return cache.get(node);
|
||||
}
|
||||
const res = reducer.reduceYieldGeneratorExpression(node, arg);
|
||||
cache.set(node, res);
|
||||
return res;
|
||||
},
|
||||
};
|
||||
};
|
|
@ -0,0 +1,430 @@
|
|||
// Generated by generate-monoidal-reducer.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = class MonoidalReducer {
|
||||
constructor(monoid) {
|
||||
let identity = monoid.empty();
|
||||
this.identity = identity;
|
||||
let concat;
|
||||
if (monoid.prototype && typeof monoid.prototype.concat === 'function') {
|
||||
concat = Function.prototype.call.bind(monoid.prototype.concat);
|
||||
} else if (typeof monoid.concat === 'function') {
|
||||
concat = monoid.concat;
|
||||
} else {
|
||||
throw new TypeError('Monoid must provide a `concat` method');
|
||||
}
|
||||
this.append = (...args) => args.reduce(concat, identity);
|
||||
}
|
||||
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
return this.append(...elements.filter(n => n != null), rest == null ? this.identity : rest);
|
||||
}
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
return this.append(...elements.filter(n => n != null), rest == null ? this.identity : rest);
|
||||
}
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
return this.append(...elements.filter(n => n != null));
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
return this.append(params, body);
|
||||
}
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
return this.append(binding, expression);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? this.identity : init);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
return this.append(name, binding);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
return this.append(binding, init);
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
return this.append(left, right);
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? this.identity : init);
|
||||
}
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
return this.append(name, binding);
|
||||
}
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
return this.append(binding, init);
|
||||
}
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
return this.append(...statements);
|
||||
}
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
return block;
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
return this.append(callee, ..._arguments);
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
return this.append(binding == null ? this.identity : binding, body);
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
return this.append(name, _super == null ? this.identity : _super, ...elements);
|
||||
}
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
return method;
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
return this.append(name == null ? this.identity : name, _super == null ? this.identity : _super, ...elements);
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
return this.append(binding, expression);
|
||||
}
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
return this.append(object, expression);
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
return this.append(object, expression);
|
||||
}
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
return this.append(test, consequent, alternate);
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
return this.append(name, expression);
|
||||
}
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDirective(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
return this.append(body, test);
|
||||
}
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
return declaration;
|
||||
}
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
return body;
|
||||
}
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
return this.append(...namedExports);
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
return name;
|
||||
}
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
return this.append(...namedExports);
|
||||
}
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
return this.append(init == null ? this.identity : init, test == null ? this.identity : test, update == null ? this.identity : update, body);
|
||||
}
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
return this.append(...items, rest == null ? this.identity : rest);
|
||||
}
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
return this.append(...directives, ...statements);
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
return this.append(name, params, body);
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
return this.append(name == null ? this.identity : name, params, body);
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
return this.append(name, body);
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
return this.append(test, consequent, alternate == null ? this.identity : alternate);
|
||||
}
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
return this.append(defaultBinding == null ? this.identity : defaultBinding, ...namedImports);
|
||||
}
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
return this.append(defaultBinding == null ? this.identity : defaultBinding, namespaceBinding);
|
||||
}
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
return binding;
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
return body;
|
||||
}
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
return this.append(name, params, body);
|
||||
}
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
return this.append(...directives, ...items);
|
||||
}
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
return this.append(callee, ..._arguments);
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
return this.append(...properties, rest == null ? this.identity : rest);
|
||||
}
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
return this.append(...properties, rest == null ? this.identity : rest);
|
||||
}
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
return this.append(...properties);
|
||||
}
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
return expression == null ? this.identity : expression;
|
||||
}
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
return this.append(...directives, ...statements);
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
return this.append(name, param, body);
|
||||
}
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
return name;
|
||||
}
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
return object;
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
return object;
|
||||
}
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceSuper(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
return this.append(test, ...consequent);
|
||||
}
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
return this.append(...consequent);
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
return this.append(discriminant, ...cases);
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
return this.append(discriminant, ...preDefaultCases, defaultCase, ...postDefaultCases);
|
||||
}
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
return this.append(tag == null ? this.identity : tag, ...elements);
|
||||
}
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
return this.append(body, catchClause);
|
||||
}
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
return this.append(body, catchClause == null ? this.identity : catchClause, finalizer);
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
return operand;
|
||||
}
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
return operand;
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
return this.append(...declarators);
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
return declaration;
|
||||
}
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? this.identity : init);
|
||||
}
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
return this.append(test, body);
|
||||
}
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
return this.append(object, body);
|
||||
}
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
return expression == null ? this.identity : expression;
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
return expression;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,418 @@
|
|||
// Generated by generate-director.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const director = {
|
||||
ArrayAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceArrayAssignmentTarget(node, { elements: node.elements.map(v => v && (() => this[v.type](reducer, v))), rest: node.rest && (() => this[node.rest.type](reducer, node.rest)) });
|
||||
},
|
||||
|
||||
ArrayBinding(reducer, node) {
|
||||
return reducer.reduceArrayBinding(node, { elements: node.elements.map(v => v && (() => this[v.type](reducer, v))), rest: node.rest && (() => this[node.rest.type](reducer, node.rest)) });
|
||||
},
|
||||
|
||||
ArrayExpression(reducer, node) {
|
||||
return reducer.reduceArrayExpression(node, { elements: node.elements.map(v => v && (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
ArrowExpression(reducer, node) {
|
||||
return reducer.reduceArrowExpression(node, { params: (() => this.FormalParameters(reducer, node.params)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
AssignmentExpression(reducer, node) {
|
||||
return reducer.reduceAssignmentExpression(node, { binding: (() => this[node.binding.type](reducer, node.binding)), expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
AssignmentTargetIdentifier(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetIdentifier(node);
|
||||
},
|
||||
|
||||
AssignmentTargetPropertyIdentifier(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetPropertyIdentifier(node, { binding: (() => this.AssignmentTargetIdentifier(reducer, node.binding)), init: node.init && (() => this[node.init.type](reducer, node.init)) });
|
||||
},
|
||||
|
||||
AssignmentTargetPropertyProperty(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetPropertyProperty(node, { name: (() => this[node.name.type](reducer, node.name)), binding: (() => this[node.binding.type](reducer, node.binding)) });
|
||||
},
|
||||
|
||||
AssignmentTargetWithDefault(reducer, node) {
|
||||
return reducer.reduceAssignmentTargetWithDefault(node, { binding: (() => this[node.binding.type](reducer, node.binding)), init: (() => this[node.init.type](reducer, node.init)) });
|
||||
},
|
||||
|
||||
AwaitExpression(reducer, node) {
|
||||
return reducer.reduceAwaitExpression(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
BinaryExpression(reducer, node) {
|
||||
return reducer.reduceBinaryExpression(node, { left: (() => this[node.left.type](reducer, node.left)), right: (() => this[node.right.type](reducer, node.right)) });
|
||||
},
|
||||
|
||||
BindingIdentifier(reducer, node) {
|
||||
return reducer.reduceBindingIdentifier(node);
|
||||
},
|
||||
|
||||
BindingPropertyIdentifier(reducer, node) {
|
||||
return reducer.reduceBindingPropertyIdentifier(node, { binding: (() => this.BindingIdentifier(reducer, node.binding)), init: node.init && (() => this[node.init.type](reducer, node.init)) });
|
||||
},
|
||||
|
||||
BindingPropertyProperty(reducer, node) {
|
||||
return reducer.reduceBindingPropertyProperty(node, { name: (() => this[node.name.type](reducer, node.name)), binding: (() => this[node.binding.type](reducer, node.binding)) });
|
||||
},
|
||||
|
||||
BindingWithDefault(reducer, node) {
|
||||
return reducer.reduceBindingWithDefault(node, { binding: (() => this[node.binding.type](reducer, node.binding)), init: (() => this[node.init.type](reducer, node.init)) });
|
||||
},
|
||||
|
||||
Block(reducer, node) {
|
||||
return reducer.reduceBlock(node, { statements: node.statements.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
BlockStatement(reducer, node) {
|
||||
return reducer.reduceBlockStatement(node, { block: (() => this.Block(reducer, node.block)) });
|
||||
},
|
||||
|
||||
BreakStatement(reducer, node) {
|
||||
return reducer.reduceBreakStatement(node);
|
||||
},
|
||||
|
||||
CallExpression(reducer, node) {
|
||||
return reducer.reduceCallExpression(node, { callee: (() => this[node.callee.type](reducer, node.callee)), arguments: node.arguments.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
CatchClause(reducer, node) {
|
||||
return reducer.reduceCatchClause(node, { binding: node.binding && (() => this[node.binding.type](reducer, node.binding)), body: (() => this.Block(reducer, node.body)) });
|
||||
},
|
||||
|
||||
ClassDeclaration(reducer, node) {
|
||||
return reducer.reduceClassDeclaration(node, { name: (() => this.BindingIdentifier(reducer, node.name)), super: node.super && (() => this[node.super.type](reducer, node.super)), elements: node.elements.map(v => (() => this.ClassElement(reducer, v))) });
|
||||
},
|
||||
|
||||
ClassElement(reducer, node) {
|
||||
return reducer.reduceClassElement(node, { method: (() => this[node.method.type](reducer, node.method)) });
|
||||
},
|
||||
|
||||
ClassExpression(reducer, node) {
|
||||
return reducer.reduceClassExpression(node, { name: node.name && (() => this.BindingIdentifier(reducer, node.name)), super: node.super && (() => this[node.super.type](reducer, node.super)), elements: node.elements.map(v => (() => this.ClassElement(reducer, v))) });
|
||||
},
|
||||
|
||||
CompoundAssignmentExpression(reducer, node) {
|
||||
return reducer.reduceCompoundAssignmentExpression(node, { binding: (() => this[node.binding.type](reducer, node.binding)), expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
ComputedMemberAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceComputedMemberAssignmentTarget(node, { object: (() => this[node.object.type](reducer, node.object)), expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
ComputedMemberExpression(reducer, node) {
|
||||
return reducer.reduceComputedMemberExpression(node, { object: (() => this[node.object.type](reducer, node.object)), expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
ComputedPropertyName(reducer, node) {
|
||||
return reducer.reduceComputedPropertyName(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
ConditionalExpression(reducer, node) {
|
||||
return reducer.reduceConditionalExpression(node, { test: (() => this[node.test.type](reducer, node.test)), consequent: (() => this[node.consequent.type](reducer, node.consequent)), alternate: (() => this[node.alternate.type](reducer, node.alternate)) });
|
||||
},
|
||||
|
||||
ContinueStatement(reducer, node) {
|
||||
return reducer.reduceContinueStatement(node);
|
||||
},
|
||||
|
||||
DataProperty(reducer, node) {
|
||||
return reducer.reduceDataProperty(node, { name: (() => this[node.name.type](reducer, node.name)), expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
DebuggerStatement(reducer, node) {
|
||||
return reducer.reduceDebuggerStatement(node);
|
||||
},
|
||||
|
||||
Directive(reducer, node) {
|
||||
return reducer.reduceDirective(node);
|
||||
},
|
||||
|
||||
DoWhileStatement(reducer, node) {
|
||||
return reducer.reduceDoWhileStatement(node, { body: (() => this[node.body.type](reducer, node.body)), test: (() => this[node.test.type](reducer, node.test)) });
|
||||
},
|
||||
|
||||
EmptyStatement(reducer, node) {
|
||||
return reducer.reduceEmptyStatement(node);
|
||||
},
|
||||
|
||||
Export(reducer, node) {
|
||||
return reducer.reduceExport(node, { declaration: (() => this[node.declaration.type](reducer, node.declaration)) });
|
||||
},
|
||||
|
||||
ExportAllFrom(reducer, node) {
|
||||
return reducer.reduceExportAllFrom(node);
|
||||
},
|
||||
|
||||
ExportDefault(reducer, node) {
|
||||
return reducer.reduceExportDefault(node, { body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
ExportFrom(reducer, node) {
|
||||
return reducer.reduceExportFrom(node, { namedExports: node.namedExports.map(v => (() => this.ExportFromSpecifier(reducer, v))) });
|
||||
},
|
||||
|
||||
ExportFromSpecifier(reducer, node) {
|
||||
return reducer.reduceExportFromSpecifier(node);
|
||||
},
|
||||
|
||||
ExportLocalSpecifier(reducer, node) {
|
||||
return reducer.reduceExportLocalSpecifier(node, { name: (() => this.IdentifierExpression(reducer, node.name)) });
|
||||
},
|
||||
|
||||
ExportLocals(reducer, node) {
|
||||
return reducer.reduceExportLocals(node, { namedExports: node.namedExports.map(v => (() => this.ExportLocalSpecifier(reducer, v))) });
|
||||
},
|
||||
|
||||
ExpressionStatement(reducer, node) {
|
||||
return reducer.reduceExpressionStatement(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
ForAwaitStatement(reducer, node) {
|
||||
return reducer.reduceForAwaitStatement(node, { left: (() => this[node.left.type](reducer, node.left)), right: (() => this[node.right.type](reducer, node.right)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
ForInStatement(reducer, node) {
|
||||
return reducer.reduceForInStatement(node, { left: (() => this[node.left.type](reducer, node.left)), right: (() => this[node.right.type](reducer, node.right)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
ForOfStatement(reducer, node) {
|
||||
return reducer.reduceForOfStatement(node, { left: (() => this[node.left.type](reducer, node.left)), right: (() => this[node.right.type](reducer, node.right)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
ForStatement(reducer, node) {
|
||||
return reducer.reduceForStatement(node, { init: node.init && (() => this[node.init.type](reducer, node.init)), test: node.test && (() => this[node.test.type](reducer, node.test)), update: node.update && (() => this[node.update.type](reducer, node.update)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
FormalParameters(reducer, node) {
|
||||
return reducer.reduceFormalParameters(node, { items: node.items.map(v => (() => this[v.type](reducer, v))), rest: node.rest && (() => this[node.rest.type](reducer, node.rest)) });
|
||||
},
|
||||
|
||||
FunctionBody(reducer, node) {
|
||||
return reducer.reduceFunctionBody(node, { directives: node.directives.map(v => (() => this.Directive(reducer, v))), statements: node.statements.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
FunctionDeclaration(reducer, node) {
|
||||
return reducer.reduceFunctionDeclaration(node, { name: (() => this.BindingIdentifier(reducer, node.name)), params: (() => this.FormalParameters(reducer, node.params)), body: (() => this.FunctionBody(reducer, node.body)) });
|
||||
},
|
||||
|
||||
FunctionExpression(reducer, node) {
|
||||
return reducer.reduceFunctionExpression(node, { name: node.name && (() => this.BindingIdentifier(reducer, node.name)), params: (() => this.FormalParameters(reducer, node.params)), body: (() => this.FunctionBody(reducer, node.body)) });
|
||||
},
|
||||
|
||||
Getter(reducer, node) {
|
||||
return reducer.reduceGetter(node, { name: (() => this[node.name.type](reducer, node.name)), body: (() => this.FunctionBody(reducer, node.body)) });
|
||||
},
|
||||
|
||||
IdentifierExpression(reducer, node) {
|
||||
return reducer.reduceIdentifierExpression(node);
|
||||
},
|
||||
|
||||
IfStatement(reducer, node) {
|
||||
return reducer.reduceIfStatement(node, { test: (() => this[node.test.type](reducer, node.test)), consequent: (() => this[node.consequent.type](reducer, node.consequent)), alternate: node.alternate && (() => this[node.alternate.type](reducer, node.alternate)) });
|
||||
},
|
||||
|
||||
Import(reducer, node) {
|
||||
return reducer.reduceImport(node, { defaultBinding: node.defaultBinding && (() => this.BindingIdentifier(reducer, node.defaultBinding)), namedImports: node.namedImports.map(v => (() => this.ImportSpecifier(reducer, v))) });
|
||||
},
|
||||
|
||||
ImportNamespace(reducer, node) {
|
||||
return reducer.reduceImportNamespace(node, { defaultBinding: node.defaultBinding && (() => this.BindingIdentifier(reducer, node.defaultBinding)), namespaceBinding: (() => this.BindingIdentifier(reducer, node.namespaceBinding)) });
|
||||
},
|
||||
|
||||
ImportSpecifier(reducer, node) {
|
||||
return reducer.reduceImportSpecifier(node, { binding: (() => this.BindingIdentifier(reducer, node.binding)) });
|
||||
},
|
||||
|
||||
LabeledStatement(reducer, node) {
|
||||
return reducer.reduceLabeledStatement(node, { body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
LiteralBooleanExpression(reducer, node) {
|
||||
return reducer.reduceLiteralBooleanExpression(node);
|
||||
},
|
||||
|
||||
LiteralInfinityExpression(reducer, node) {
|
||||
return reducer.reduceLiteralInfinityExpression(node);
|
||||
},
|
||||
|
||||
LiteralNullExpression(reducer, node) {
|
||||
return reducer.reduceLiteralNullExpression(node);
|
||||
},
|
||||
|
||||
LiteralNumericExpression(reducer, node) {
|
||||
return reducer.reduceLiteralNumericExpression(node);
|
||||
},
|
||||
|
||||
LiteralRegExpExpression(reducer, node) {
|
||||
return reducer.reduceLiteralRegExpExpression(node);
|
||||
},
|
||||
|
||||
LiteralStringExpression(reducer, node) {
|
||||
return reducer.reduceLiteralStringExpression(node);
|
||||
},
|
||||
|
||||
Method(reducer, node) {
|
||||
return reducer.reduceMethod(node, { name: (() => this[node.name.type](reducer, node.name)), params: (() => this.FormalParameters(reducer, node.params)), body: (() => this.FunctionBody(reducer, node.body)) });
|
||||
},
|
||||
|
||||
Module(reducer, node) {
|
||||
return reducer.reduceModule(node, { directives: node.directives.map(v => (() => this.Directive(reducer, v))), items: node.items.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
NewExpression(reducer, node) {
|
||||
return reducer.reduceNewExpression(node, { callee: (() => this[node.callee.type](reducer, node.callee)), arguments: node.arguments.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
NewTargetExpression(reducer, node) {
|
||||
return reducer.reduceNewTargetExpression(node);
|
||||
},
|
||||
|
||||
ObjectAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceObjectAssignmentTarget(node, { properties: node.properties.map(v => (() => this[v.type](reducer, v))), rest: node.rest && (() => this[node.rest.type](reducer, node.rest)) });
|
||||
},
|
||||
|
||||
ObjectBinding(reducer, node) {
|
||||
return reducer.reduceObjectBinding(node, { properties: node.properties.map(v => (() => this[v.type](reducer, v))), rest: node.rest && (() => this.BindingIdentifier(reducer, node.rest)) });
|
||||
},
|
||||
|
||||
ObjectExpression(reducer, node) {
|
||||
return reducer.reduceObjectExpression(node, { properties: node.properties.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
ReturnStatement(reducer, node) {
|
||||
return reducer.reduceReturnStatement(node, { expression: node.expression && (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
Script(reducer, node) {
|
||||
return reducer.reduceScript(node, { directives: node.directives.map(v => (() => this.Directive(reducer, v))), statements: node.statements.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
Setter(reducer, node) {
|
||||
return reducer.reduceSetter(node, { name: (() => this[node.name.type](reducer, node.name)), param: (() => this[node.param.type](reducer, node.param)), body: (() => this.FunctionBody(reducer, node.body)) });
|
||||
},
|
||||
|
||||
ShorthandProperty(reducer, node) {
|
||||
return reducer.reduceShorthandProperty(node, { name: (() => this.IdentifierExpression(reducer, node.name)) });
|
||||
},
|
||||
|
||||
SpreadElement(reducer, node) {
|
||||
return reducer.reduceSpreadElement(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
SpreadProperty(reducer, node) {
|
||||
return reducer.reduceSpreadProperty(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
StaticMemberAssignmentTarget(reducer, node) {
|
||||
return reducer.reduceStaticMemberAssignmentTarget(node, { object: (() => this[node.object.type](reducer, node.object)) });
|
||||
},
|
||||
|
||||
StaticMemberExpression(reducer, node) {
|
||||
return reducer.reduceStaticMemberExpression(node, { object: (() => this[node.object.type](reducer, node.object)) });
|
||||
},
|
||||
|
||||
StaticPropertyName(reducer, node) {
|
||||
return reducer.reduceStaticPropertyName(node);
|
||||
},
|
||||
|
||||
Super(reducer, node) {
|
||||
return reducer.reduceSuper(node);
|
||||
},
|
||||
|
||||
SwitchCase(reducer, node) {
|
||||
return reducer.reduceSwitchCase(node, { test: (() => this[node.test.type](reducer, node.test)), consequent: node.consequent.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
SwitchDefault(reducer, node) {
|
||||
return reducer.reduceSwitchDefault(node, { consequent: node.consequent.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
SwitchStatement(reducer, node) {
|
||||
return reducer.reduceSwitchStatement(node, { discriminant: (() => this[node.discriminant.type](reducer, node.discriminant)), cases: node.cases.map(v => (() => this.SwitchCase(reducer, v))) });
|
||||
},
|
||||
|
||||
SwitchStatementWithDefault(reducer, node) {
|
||||
return reducer.reduceSwitchStatementWithDefault(node, { discriminant: (() => this[node.discriminant.type](reducer, node.discriminant)), preDefaultCases: node.preDefaultCases.map(v => (() => this.SwitchCase(reducer, v))), defaultCase: (() => this.SwitchDefault(reducer, node.defaultCase)), postDefaultCases: node.postDefaultCases.map(v => (() => this.SwitchCase(reducer, v))) });
|
||||
},
|
||||
|
||||
TemplateElement(reducer, node) {
|
||||
return reducer.reduceTemplateElement(node);
|
||||
},
|
||||
|
||||
TemplateExpression(reducer, node) {
|
||||
return reducer.reduceTemplateExpression(node, { tag: node.tag && (() => this[node.tag.type](reducer, node.tag)), elements: node.elements.map(v => (() => this[v.type](reducer, v))) });
|
||||
},
|
||||
|
||||
ThisExpression(reducer, node) {
|
||||
return reducer.reduceThisExpression(node);
|
||||
},
|
||||
|
||||
ThrowStatement(reducer, node) {
|
||||
return reducer.reduceThrowStatement(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
TryCatchStatement(reducer, node) {
|
||||
return reducer.reduceTryCatchStatement(node, { body: (() => this.Block(reducer, node.body)), catchClause: (() => this.CatchClause(reducer, node.catchClause)) });
|
||||
},
|
||||
|
||||
TryFinallyStatement(reducer, node) {
|
||||
return reducer.reduceTryFinallyStatement(node, { body: (() => this.Block(reducer, node.body)), catchClause: node.catchClause && (() => this.CatchClause(reducer, node.catchClause)), finalizer: (() => this.Block(reducer, node.finalizer)) });
|
||||
},
|
||||
|
||||
UnaryExpression(reducer, node) {
|
||||
return reducer.reduceUnaryExpression(node, { operand: (() => this[node.operand.type](reducer, node.operand)) });
|
||||
},
|
||||
|
||||
UpdateExpression(reducer, node) {
|
||||
return reducer.reduceUpdateExpression(node, { operand: (() => this[node.operand.type](reducer, node.operand)) });
|
||||
},
|
||||
|
||||
VariableDeclaration(reducer, node) {
|
||||
return reducer.reduceVariableDeclaration(node, { declarators: node.declarators.map(v => (() => this.VariableDeclarator(reducer, v))) });
|
||||
},
|
||||
|
||||
VariableDeclarationStatement(reducer, node) {
|
||||
return reducer.reduceVariableDeclarationStatement(node, { declaration: (() => this.VariableDeclaration(reducer, node.declaration)) });
|
||||
},
|
||||
|
||||
VariableDeclarator(reducer, node) {
|
||||
return reducer.reduceVariableDeclarator(node, { binding: (() => this[node.binding.type](reducer, node.binding)), init: node.init && (() => this[node.init.type](reducer, node.init)) });
|
||||
},
|
||||
|
||||
WhileStatement(reducer, node) {
|
||||
return reducer.reduceWhileStatement(node, { test: (() => this[node.test.type](reducer, node.test)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
WithStatement(reducer, node) {
|
||||
return reducer.reduceWithStatement(node, { object: (() => this[node.object.type](reducer, node.object)), body: (() => this[node.body.type](reducer, node.body)) });
|
||||
},
|
||||
|
||||
YieldExpression(reducer, node) {
|
||||
return reducer.reduceYieldExpression(node, { expression: node.expression && (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
|
||||
YieldGeneratorExpression(reducer, node) {
|
||||
return reducer.reduceYieldGeneratorExpression(node, { expression: (() => this[node.expression.type](reducer, node.expression)) });
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = function thunkedReduce(reducer, node) {
|
||||
return director[node.type](reducer, node);
|
||||
};
|
|
@ -0,0 +1,444 @@
|
|||
// Generated by generate-monoidal-reducer.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Shift = require('shift-ast');
|
||||
|
||||
module.exports = class MonoidalReducer {
|
||||
constructor(monoid) {
|
||||
let identity = monoid.empty();
|
||||
this.identity = identity;
|
||||
|
||||
let concatThunk;
|
||||
if (monoid.prototype && typeof monoid.prototype.concatThunk === 'function') {
|
||||
concatThunk = Function.prototype.call.bind(monoid.prototype.concatThunk);
|
||||
} else if (typeof monoid.concatThunk === 'function') {
|
||||
concatThunk = monoid.concatThunk;
|
||||
} else {
|
||||
let concat;
|
||||
if (monoid.prototype && typeof monoid.prototype.concat === 'function') {
|
||||
concat = Function.prototype.call.bind(monoid.prototype.concat);
|
||||
} else if (typeof monoid.concat === 'function') {
|
||||
concat = monoid.concat;
|
||||
} else {
|
||||
throw new TypeError('Monoid must provide a `concatThunk` or `concat` method');
|
||||
}
|
||||
if (typeof monoid.isAbsorbing === 'function') {
|
||||
let isAbsorbing = monoid.isAbsorbing;
|
||||
concatThunk = (a, b) => isAbsorbing(a) ? a : concat(a, b());
|
||||
} else {
|
||||
concatThunk = (a, b) => concat(a, b());
|
||||
}
|
||||
}
|
||||
this.append = (...args) => args.reduce(concatThunk, identity);
|
||||
}
|
||||
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
return this.append(...elements.filter(n => n != null), rest == null ? () => this.identity : rest);
|
||||
}
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
return this.append(...elements.filter(n => n != null), rest == null ? () => this.identity : rest);
|
||||
}
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
return this.append(...elements.filter(n => n != null));
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
return this.append(params, body);
|
||||
}
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
return this.append(binding, expression);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? () => this.identity : init);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
return this.append(name, binding);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
return this.append(binding, init);
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
return this.append(left, right);
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? () => this.identity : init);
|
||||
}
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
return this.append(name, binding);
|
||||
}
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
return this.append(binding, init);
|
||||
}
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
return this.append(...statements);
|
||||
}
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
return block();
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
return this.append(callee, ..._arguments);
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
return this.append(binding == null ? () => this.identity : binding, body);
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
return this.append(name, _super == null ? () => this.identity : _super, ...elements);
|
||||
}
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
return method();
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
return this.append(name == null ? () => this.identity : name, _super == null ? () => this.identity : _super, ...elements);
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
return this.append(binding, expression);
|
||||
}
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
return this.append(object, expression);
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
return this.append(object, expression);
|
||||
}
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
return this.append(test, consequent, alternate);
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
return this.append(name, expression);
|
||||
}
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDirective(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
return this.append(body, test);
|
||||
}
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
return declaration();
|
||||
}
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
return body();
|
||||
}
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
return this.append(...namedExports);
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
return name();
|
||||
}
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
return this.append(...namedExports);
|
||||
}
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
return this.append(left, right, body);
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
return this.append(init == null ? () => this.identity : init, test == null ? () => this.identity : test, update == null ? () => this.identity : update, body);
|
||||
}
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
return this.append(...items, rest == null ? () => this.identity : rest);
|
||||
}
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
return this.append(...directives, ...statements);
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
return this.append(name, params, body);
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
return this.append(name == null ? () => this.identity : name, params, body);
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
return this.append(name, body);
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
return this.append(test, consequent, alternate == null ? () => this.identity : alternate);
|
||||
}
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
return this.append(defaultBinding == null ? () => this.identity : defaultBinding, ...namedImports);
|
||||
}
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
return this.append(defaultBinding == null ? () => this.identity : defaultBinding, namespaceBinding);
|
||||
}
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
return binding();
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
return body();
|
||||
}
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
return this.append(name, params, body);
|
||||
}
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
return this.append(...directives, ...items);
|
||||
}
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
return this.append(callee, ..._arguments);
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
return this.append(...properties, rest == null ? () => this.identity : rest);
|
||||
}
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
return this.append(...properties, rest == null ? () => this.identity : rest);
|
||||
}
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
return this.append(...properties);
|
||||
}
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
return expression == null ? this.identity : expression();
|
||||
}
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
return this.append(...directives, ...statements);
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
return this.append(name, param, body);
|
||||
}
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
return name();
|
||||
}
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
return object();
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
return object();
|
||||
}
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceSuper(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
return this.append(test, ...consequent);
|
||||
}
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
return this.append(...consequent);
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
return this.append(discriminant, ...cases);
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
return this.append(discriminant, ...preDefaultCases, defaultCase, ...postDefaultCases);
|
||||
}
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
return this.append(tag == null ? () => this.identity : tag, ...elements);
|
||||
}
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
return this.append(body, catchClause);
|
||||
}
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
return this.append(body, catchClause == null ? () => this.identity : catchClause, finalizer);
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
return operand();
|
||||
}
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
return operand();
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
return this.append(...declarators);
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
return declaration();
|
||||
}
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
return this.append(binding, init == null ? () => this.identity : init);
|
||||
}
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
return this.append(test, body);
|
||||
}
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
return this.append(object, body);
|
||||
}
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
return expression == null ? this.identity : expression();
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
return expression();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,416 @@
|
|||
// Generated by generate-thunkify.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
module.exports = function thunkifyClass(reducerClass) {
|
||||
return class extends reducerClass {
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
return super.reduceArrayAssignmentTarget(node, { elements: elements.map(n => n == null ? null : n()), rest: rest == null ? null : rest() });
|
||||
}
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
return super.reduceArrayBinding(node, { elements: elements.map(n => n == null ? null : n()), rest: rest == null ? null : rest() });
|
||||
}
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
return super.reduceArrayExpression(node, { elements: elements.map(n => n == null ? null : n()) });
|
||||
}
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
return super.reduceArrowExpression(node, { params: params(), body: body() });
|
||||
}
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
return super.reduceAssignmentExpression(node, { binding: binding(), expression: expression() });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return super.reduceAssignmentTargetIdentifier(node);
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
return super.reduceAssignmentTargetPropertyIdentifier(node, { binding: binding(), init: init == null ? null : init() });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
return super.reduceAssignmentTargetPropertyProperty(node, { name: name(), binding: binding() });
|
||||
}
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
return super.reduceAssignmentTargetWithDefault(node, { binding: binding(), init: init() });
|
||||
}
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return super.reduceAwaitExpression(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
return super.reduceBinaryExpression(node, { left: left(), right: right() });
|
||||
}
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return super.reduceBindingIdentifier(node);
|
||||
}
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
return super.reduceBindingPropertyIdentifier(node, { binding: binding(), init: init == null ? null : init() });
|
||||
}
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
return super.reduceBindingPropertyProperty(node, { name: name(), binding: binding() });
|
||||
}
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
return super.reduceBindingWithDefault(node, { binding: binding(), init: init() });
|
||||
}
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
return super.reduceBlock(node, { statements: statements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
return super.reduceBlockStatement(node, { block: block() });
|
||||
}
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return super.reduceBreakStatement(node);
|
||||
}
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
return super.reduceCallExpression(node, { callee: callee(), arguments: _arguments.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
return super.reduceCatchClause(node, { binding: binding == null ? null : binding(), body: body() });
|
||||
}
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
return super.reduceClassDeclaration(node, { name: name(), super: _super == null ? null : _super(), elements: elements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
return super.reduceClassElement(node, { method: method() });
|
||||
}
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
return super.reduceClassExpression(node, { name: name == null ? null : name(), super: _super == null ? null : _super(), elements: elements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
return super.reduceCompoundAssignmentExpression(node, { binding: binding(), expression: expression() });
|
||||
}
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
return super.reduceComputedMemberAssignmentTarget(node, { object: object(), expression: expression() });
|
||||
}
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
return super.reduceComputedMemberExpression(node, { object: object(), expression: expression() });
|
||||
}
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
return super.reduceComputedPropertyName(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
return super.reduceConditionalExpression(node, { test: test(), consequent: consequent(), alternate: alternate() });
|
||||
}
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return super.reduceContinueStatement(node);
|
||||
}
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
return super.reduceDataProperty(node, { name: name(), expression: expression() });
|
||||
}
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return super.reduceDebuggerStatement(node);
|
||||
}
|
||||
|
||||
reduceDirective(node) {
|
||||
return super.reduceDirective(node);
|
||||
}
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
return super.reduceDoWhileStatement(node, { body: body(), test: test() });
|
||||
}
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return super.reduceEmptyStatement(node);
|
||||
}
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
return super.reduceExport(node, { declaration: declaration() });
|
||||
}
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return super.reduceExportAllFrom(node);
|
||||
}
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
return super.reduceExportDefault(node, { body: body() });
|
||||
}
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
return super.reduceExportFrom(node, { namedExports: namedExports.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return super.reduceExportFromSpecifier(node);
|
||||
}
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
return super.reduceExportLocalSpecifier(node, { name: name() });
|
||||
}
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
return super.reduceExportLocals(node, { namedExports: namedExports.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
return super.reduceExpressionStatement(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
return super.reduceForAwaitStatement(node, { left: left(), right: right(), body: body() });
|
||||
}
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
return super.reduceForInStatement(node, { left: left(), right: right(), body: body() });
|
||||
}
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
return super.reduceForOfStatement(node, { left: left(), right: right(), body: body() });
|
||||
}
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
return super.reduceForStatement(node, { init: init == null ? null : init(), test: test == null ? null : test(), update: update == null ? null : update(), body: body() });
|
||||
}
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
return super.reduceFormalParameters(node, { items: items.map(n => n()), rest: rest == null ? null : rest() });
|
||||
}
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
return super.reduceFunctionBody(node, { directives: directives.map(n => n()), statements: statements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
return super.reduceFunctionDeclaration(node, { name: name(), params: params(), body: body() });
|
||||
}
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
return super.reduceFunctionExpression(node, { name: name == null ? null : name(), params: params(), body: body() });
|
||||
}
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
return super.reduceGetter(node, { name: name(), body: body() });
|
||||
}
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return super.reduceIdentifierExpression(node);
|
||||
}
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
return super.reduceIfStatement(node, { test: test(), consequent: consequent(), alternate: alternate == null ? null : alternate() });
|
||||
}
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
return super.reduceImport(node, { defaultBinding: defaultBinding == null ? null : defaultBinding(), namedImports: namedImports.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
return super.reduceImportNamespace(node, { defaultBinding: defaultBinding == null ? null : defaultBinding(), namespaceBinding: namespaceBinding() });
|
||||
}
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
return super.reduceImportSpecifier(node, { binding: binding() });
|
||||
}
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
return super.reduceLabeledStatement(node, { body: body() });
|
||||
}
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return super.reduceLiteralBooleanExpression(node);
|
||||
}
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return super.reduceLiteralInfinityExpression(node);
|
||||
}
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return super.reduceLiteralNullExpression(node);
|
||||
}
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return super.reduceLiteralNumericExpression(node);
|
||||
}
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return super.reduceLiteralRegExpExpression(node);
|
||||
}
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return super.reduceLiteralStringExpression(node);
|
||||
}
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
return super.reduceMethod(node, { name: name(), params: params(), body: body() });
|
||||
}
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
return super.reduceModule(node, { directives: directives.map(n => n()), items: items.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
return super.reduceNewExpression(node, { callee: callee(), arguments: _arguments.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return super.reduceNewTargetExpression(node);
|
||||
}
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
return super.reduceObjectAssignmentTarget(node, { properties: properties.map(n => n()), rest: rest == null ? null : rest() });
|
||||
}
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
return super.reduceObjectBinding(node, { properties: properties.map(n => n()), rest: rest == null ? null : rest() });
|
||||
}
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
return super.reduceObjectExpression(node, { properties: properties.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
return super.reduceReturnStatement(node, { expression: expression == null ? null : expression() });
|
||||
}
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
return super.reduceScript(node, { directives: directives.map(n => n()), statements: statements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
return super.reduceSetter(node, { name: name(), param: param(), body: body() });
|
||||
}
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
return super.reduceShorthandProperty(node, { name: name() });
|
||||
}
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
return super.reduceSpreadElement(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
return super.reduceSpreadProperty(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
return super.reduceStaticMemberAssignmentTarget(node, { object: object() });
|
||||
}
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
return super.reduceStaticMemberExpression(node, { object: object() });
|
||||
}
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return super.reduceStaticPropertyName(node);
|
||||
}
|
||||
|
||||
reduceSuper(node) {
|
||||
return super.reduceSuper(node);
|
||||
}
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
return super.reduceSwitchCase(node, { test: test(), consequent: consequent.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
return super.reduceSwitchDefault(node, { consequent: consequent.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
return super.reduceSwitchStatement(node, { discriminant: discriminant(), cases: cases.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
return super.reduceSwitchStatementWithDefault(node, { discriminant: discriminant(), preDefaultCases: preDefaultCases.map(n => n()), defaultCase: defaultCase(), postDefaultCases: postDefaultCases.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return super.reduceTemplateElement(node);
|
||||
}
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
return super.reduceTemplateExpression(node, { tag: tag == null ? null : tag(), elements: elements.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return super.reduceThisExpression(node);
|
||||
}
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
return super.reduceThrowStatement(node, { expression: expression() });
|
||||
}
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
return super.reduceTryCatchStatement(node, { body: body(), catchClause: catchClause() });
|
||||
}
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
return super.reduceTryFinallyStatement(node, { body: body(), catchClause: catchClause == null ? null : catchClause(), finalizer: finalizer() });
|
||||
}
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
return super.reduceUnaryExpression(node, { operand: operand() });
|
||||
}
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
return super.reduceUpdateExpression(node, { operand: operand() });
|
||||
}
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
return super.reduceVariableDeclaration(node, { declarators: declarators.map(n => n()) });
|
||||
}
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
return super.reduceVariableDeclarationStatement(node, { declaration: declaration() });
|
||||
}
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
return super.reduceVariableDeclarator(node, { binding: binding(), init: init == null ? null : init() });
|
||||
}
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
return super.reduceWhileStatement(node, { test: test(), body: body() });
|
||||
}
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
return super.reduceWithStatement(node, { object: object(), body: body() });
|
||||
}
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
return super.reduceYieldExpression(node, { expression: expression == null ? null : expression() });
|
||||
}
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
return super.reduceYieldGeneratorExpression(node, { expression: expression() });
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,416 @@
|
|||
// Generated by generate-thunkify.js
|
||||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
module.exports = function thunkify(reducer) {
|
||||
return {
|
||||
reduceArrayAssignmentTarget(node, { elements, rest }) {
|
||||
return reducer.reduceArrayAssignmentTarget(node, { elements: elements.map(n => n == null ? null : n()), rest: rest == null ? null : rest() });
|
||||
},
|
||||
|
||||
reduceArrayBinding(node, { elements, rest }) {
|
||||
return reducer.reduceArrayBinding(node, { elements: elements.map(n => n == null ? null : n()), rest: rest == null ? null : rest() });
|
||||
},
|
||||
|
||||
reduceArrayExpression(node, { elements }) {
|
||||
return reducer.reduceArrayExpression(node, { elements: elements.map(n => n == null ? null : n()) });
|
||||
},
|
||||
|
||||
reduceArrowExpression(node, { params, body }) {
|
||||
return reducer.reduceArrowExpression(node, { params: params(), body: body() });
|
||||
},
|
||||
|
||||
reduceAssignmentExpression(node, { binding, expression }) {
|
||||
return reducer.reduceAssignmentExpression(node, { binding: binding(), expression: expression() });
|
||||
},
|
||||
|
||||
reduceAssignmentTargetIdentifier(node) {
|
||||
return reducer.reduceAssignmentTargetIdentifier(node);
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyIdentifier(node, { binding, init }) {
|
||||
return reducer.reduceAssignmentTargetPropertyIdentifier(node, { binding: binding(), init: init == null ? null : init() });
|
||||
},
|
||||
|
||||
reduceAssignmentTargetPropertyProperty(node, { name, binding }) {
|
||||
return reducer.reduceAssignmentTargetPropertyProperty(node, { name: name(), binding: binding() });
|
||||
},
|
||||
|
||||
reduceAssignmentTargetWithDefault(node, { binding, init }) {
|
||||
return reducer.reduceAssignmentTargetWithDefault(node, { binding: binding(), init: init() });
|
||||
},
|
||||
|
||||
reduceAwaitExpression(node, { expression }) {
|
||||
return reducer.reduceAwaitExpression(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceBinaryExpression(node, { left, right }) {
|
||||
return reducer.reduceBinaryExpression(node, { left: left(), right: right() });
|
||||
},
|
||||
|
||||
reduceBindingIdentifier(node) {
|
||||
return reducer.reduceBindingIdentifier(node);
|
||||
},
|
||||
|
||||
reduceBindingPropertyIdentifier(node, { binding, init }) {
|
||||
return reducer.reduceBindingPropertyIdentifier(node, { binding: binding(), init: init == null ? null : init() });
|
||||
},
|
||||
|
||||
reduceBindingPropertyProperty(node, { name, binding }) {
|
||||
return reducer.reduceBindingPropertyProperty(node, { name: name(), binding: binding() });
|
||||
},
|
||||
|
||||
reduceBindingWithDefault(node, { binding, init }) {
|
||||
return reducer.reduceBindingWithDefault(node, { binding: binding(), init: init() });
|
||||
},
|
||||
|
||||
reduceBlock(node, { statements }) {
|
||||
return reducer.reduceBlock(node, { statements: statements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceBlockStatement(node, { block }) {
|
||||
return reducer.reduceBlockStatement(node, { block: block() });
|
||||
},
|
||||
|
||||
reduceBreakStatement(node) {
|
||||
return reducer.reduceBreakStatement(node);
|
||||
},
|
||||
|
||||
reduceCallExpression(node, { callee, arguments: _arguments }) {
|
||||
return reducer.reduceCallExpression(node, { callee: callee(), arguments: _arguments.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceCatchClause(node, { binding, body }) {
|
||||
return reducer.reduceCatchClause(node, { binding: binding == null ? null : binding(), body: body() });
|
||||
},
|
||||
|
||||
reduceClassDeclaration(node, { name, super: _super, elements }) {
|
||||
return reducer.reduceClassDeclaration(node, { name: name(), super: _super == null ? null : _super(), elements: elements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceClassElement(node, { method }) {
|
||||
return reducer.reduceClassElement(node, { method: method() });
|
||||
},
|
||||
|
||||
reduceClassExpression(node, { name, super: _super, elements }) {
|
||||
return reducer.reduceClassExpression(node, { name: name == null ? null : name(), super: _super == null ? null : _super(), elements: elements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceCompoundAssignmentExpression(node, { binding, expression }) {
|
||||
return reducer.reduceCompoundAssignmentExpression(node, { binding: binding(), expression: expression() });
|
||||
},
|
||||
|
||||
reduceComputedMemberAssignmentTarget(node, { object, expression }) {
|
||||
return reducer.reduceComputedMemberAssignmentTarget(node, { object: object(), expression: expression() });
|
||||
},
|
||||
|
||||
reduceComputedMemberExpression(node, { object, expression }) {
|
||||
return reducer.reduceComputedMemberExpression(node, { object: object(), expression: expression() });
|
||||
},
|
||||
|
||||
reduceComputedPropertyName(node, { expression }) {
|
||||
return reducer.reduceComputedPropertyName(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceConditionalExpression(node, { test, consequent, alternate }) {
|
||||
return reducer.reduceConditionalExpression(node, { test: test(), consequent: consequent(), alternate: alternate() });
|
||||
},
|
||||
|
||||
reduceContinueStatement(node) {
|
||||
return reducer.reduceContinueStatement(node);
|
||||
},
|
||||
|
||||
reduceDataProperty(node, { name, expression }) {
|
||||
return reducer.reduceDataProperty(node, { name: name(), expression: expression() });
|
||||
},
|
||||
|
||||
reduceDebuggerStatement(node) {
|
||||
return reducer.reduceDebuggerStatement(node);
|
||||
},
|
||||
|
||||
reduceDirective(node) {
|
||||
return reducer.reduceDirective(node);
|
||||
},
|
||||
|
||||
reduceDoWhileStatement(node, { body, test }) {
|
||||
return reducer.reduceDoWhileStatement(node, { body: body(), test: test() });
|
||||
},
|
||||
|
||||
reduceEmptyStatement(node) {
|
||||
return reducer.reduceEmptyStatement(node);
|
||||
},
|
||||
|
||||
reduceExport(node, { declaration }) {
|
||||
return reducer.reduceExport(node, { declaration: declaration() });
|
||||
},
|
||||
|
||||
reduceExportAllFrom(node) {
|
||||
return reducer.reduceExportAllFrom(node);
|
||||
},
|
||||
|
||||
reduceExportDefault(node, { body }) {
|
||||
return reducer.reduceExportDefault(node, { body: body() });
|
||||
},
|
||||
|
||||
reduceExportFrom(node, { namedExports }) {
|
||||
return reducer.reduceExportFrom(node, { namedExports: namedExports.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceExportFromSpecifier(node) {
|
||||
return reducer.reduceExportFromSpecifier(node);
|
||||
},
|
||||
|
||||
reduceExportLocalSpecifier(node, { name }) {
|
||||
return reducer.reduceExportLocalSpecifier(node, { name: name() });
|
||||
},
|
||||
|
||||
reduceExportLocals(node, { namedExports }) {
|
||||
return reducer.reduceExportLocals(node, { namedExports: namedExports.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceExpressionStatement(node, { expression }) {
|
||||
return reducer.reduceExpressionStatement(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceForAwaitStatement(node, { left, right, body }) {
|
||||
return reducer.reduceForAwaitStatement(node, { left: left(), right: right(), body: body() });
|
||||
},
|
||||
|
||||
reduceForInStatement(node, { left, right, body }) {
|
||||
return reducer.reduceForInStatement(node, { left: left(), right: right(), body: body() });
|
||||
},
|
||||
|
||||
reduceForOfStatement(node, { left, right, body }) {
|
||||
return reducer.reduceForOfStatement(node, { left: left(), right: right(), body: body() });
|
||||
},
|
||||
|
||||
reduceForStatement(node, { init, test, update, body }) {
|
||||
return reducer.reduceForStatement(node, { init: init == null ? null : init(), test: test == null ? null : test(), update: update == null ? null : update(), body: body() });
|
||||
},
|
||||
|
||||
reduceFormalParameters(node, { items, rest }) {
|
||||
return reducer.reduceFormalParameters(node, { items: items.map(n => n()), rest: rest == null ? null : rest() });
|
||||
},
|
||||
|
||||
reduceFunctionBody(node, { directives, statements }) {
|
||||
return reducer.reduceFunctionBody(node, { directives: directives.map(n => n()), statements: statements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceFunctionDeclaration(node, { name, params, body }) {
|
||||
return reducer.reduceFunctionDeclaration(node, { name: name(), params: params(), body: body() });
|
||||
},
|
||||
|
||||
reduceFunctionExpression(node, { name, params, body }) {
|
||||
return reducer.reduceFunctionExpression(node, { name: name == null ? null : name(), params: params(), body: body() });
|
||||
},
|
||||
|
||||
reduceGetter(node, { name, body }) {
|
||||
return reducer.reduceGetter(node, { name: name(), body: body() });
|
||||
},
|
||||
|
||||
reduceIdentifierExpression(node) {
|
||||
return reducer.reduceIdentifierExpression(node);
|
||||
},
|
||||
|
||||
reduceIfStatement(node, { test, consequent, alternate }) {
|
||||
return reducer.reduceIfStatement(node, { test: test(), consequent: consequent(), alternate: alternate == null ? null : alternate() });
|
||||
},
|
||||
|
||||
reduceImport(node, { defaultBinding, namedImports }) {
|
||||
return reducer.reduceImport(node, { defaultBinding: defaultBinding == null ? null : defaultBinding(), namedImports: namedImports.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceImportNamespace(node, { defaultBinding, namespaceBinding }) {
|
||||
return reducer.reduceImportNamespace(node, { defaultBinding: defaultBinding == null ? null : defaultBinding(), namespaceBinding: namespaceBinding() });
|
||||
},
|
||||
|
||||
reduceImportSpecifier(node, { binding }) {
|
||||
return reducer.reduceImportSpecifier(node, { binding: binding() });
|
||||
},
|
||||
|
||||
reduceLabeledStatement(node, { body }) {
|
||||
return reducer.reduceLabeledStatement(node, { body: body() });
|
||||
},
|
||||
|
||||
reduceLiteralBooleanExpression(node) {
|
||||
return reducer.reduceLiteralBooleanExpression(node);
|
||||
},
|
||||
|
||||
reduceLiteralInfinityExpression(node) {
|
||||
return reducer.reduceLiteralInfinityExpression(node);
|
||||
},
|
||||
|
||||
reduceLiteralNullExpression(node) {
|
||||
return reducer.reduceLiteralNullExpression(node);
|
||||
},
|
||||
|
||||
reduceLiteralNumericExpression(node) {
|
||||
return reducer.reduceLiteralNumericExpression(node);
|
||||
},
|
||||
|
||||
reduceLiteralRegExpExpression(node) {
|
||||
return reducer.reduceLiteralRegExpExpression(node);
|
||||
},
|
||||
|
||||
reduceLiteralStringExpression(node) {
|
||||
return reducer.reduceLiteralStringExpression(node);
|
||||
},
|
||||
|
||||
reduceMethod(node, { name, params, body }) {
|
||||
return reducer.reduceMethod(node, { name: name(), params: params(), body: body() });
|
||||
},
|
||||
|
||||
reduceModule(node, { directives, items }) {
|
||||
return reducer.reduceModule(node, { directives: directives.map(n => n()), items: items.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceNewExpression(node, { callee, arguments: _arguments }) {
|
||||
return reducer.reduceNewExpression(node, { callee: callee(), arguments: _arguments.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceNewTargetExpression(node) {
|
||||
return reducer.reduceNewTargetExpression(node);
|
||||
},
|
||||
|
||||
reduceObjectAssignmentTarget(node, { properties, rest }) {
|
||||
return reducer.reduceObjectAssignmentTarget(node, { properties: properties.map(n => n()), rest: rest == null ? null : rest() });
|
||||
},
|
||||
|
||||
reduceObjectBinding(node, { properties, rest }) {
|
||||
return reducer.reduceObjectBinding(node, { properties: properties.map(n => n()), rest: rest == null ? null : rest() });
|
||||
},
|
||||
|
||||
reduceObjectExpression(node, { properties }) {
|
||||
return reducer.reduceObjectExpression(node, { properties: properties.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceReturnStatement(node, { expression }) {
|
||||
return reducer.reduceReturnStatement(node, { expression: expression == null ? null : expression() });
|
||||
},
|
||||
|
||||
reduceScript(node, { directives, statements }) {
|
||||
return reducer.reduceScript(node, { directives: directives.map(n => n()), statements: statements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceSetter(node, { name, param, body }) {
|
||||
return reducer.reduceSetter(node, { name: name(), param: param(), body: body() });
|
||||
},
|
||||
|
||||
reduceShorthandProperty(node, { name }) {
|
||||
return reducer.reduceShorthandProperty(node, { name: name() });
|
||||
},
|
||||
|
||||
reduceSpreadElement(node, { expression }) {
|
||||
return reducer.reduceSpreadElement(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceSpreadProperty(node, { expression }) {
|
||||
return reducer.reduceSpreadProperty(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceStaticMemberAssignmentTarget(node, { object }) {
|
||||
return reducer.reduceStaticMemberAssignmentTarget(node, { object: object() });
|
||||
},
|
||||
|
||||
reduceStaticMemberExpression(node, { object }) {
|
||||
return reducer.reduceStaticMemberExpression(node, { object: object() });
|
||||
},
|
||||
|
||||
reduceStaticPropertyName(node) {
|
||||
return reducer.reduceStaticPropertyName(node);
|
||||
},
|
||||
|
||||
reduceSuper(node) {
|
||||
return reducer.reduceSuper(node);
|
||||
},
|
||||
|
||||
reduceSwitchCase(node, { test, consequent }) {
|
||||
return reducer.reduceSwitchCase(node, { test: test(), consequent: consequent.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceSwitchDefault(node, { consequent }) {
|
||||
return reducer.reduceSwitchDefault(node, { consequent: consequent.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceSwitchStatement(node, { discriminant, cases }) {
|
||||
return reducer.reduceSwitchStatement(node, { discriminant: discriminant(), cases: cases.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceSwitchStatementWithDefault(node, { discriminant, preDefaultCases, defaultCase, postDefaultCases }) {
|
||||
return reducer.reduceSwitchStatementWithDefault(node, { discriminant: discriminant(), preDefaultCases: preDefaultCases.map(n => n()), defaultCase: defaultCase(), postDefaultCases: postDefaultCases.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceTemplateElement(node) {
|
||||
return reducer.reduceTemplateElement(node);
|
||||
},
|
||||
|
||||
reduceTemplateExpression(node, { tag, elements }) {
|
||||
return reducer.reduceTemplateExpression(node, { tag: tag == null ? null : tag(), elements: elements.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceThisExpression(node) {
|
||||
return reducer.reduceThisExpression(node);
|
||||
},
|
||||
|
||||
reduceThrowStatement(node, { expression }) {
|
||||
return reducer.reduceThrowStatement(node, { expression: expression() });
|
||||
},
|
||||
|
||||
reduceTryCatchStatement(node, { body, catchClause }) {
|
||||
return reducer.reduceTryCatchStatement(node, { body: body(), catchClause: catchClause() });
|
||||
},
|
||||
|
||||
reduceTryFinallyStatement(node, { body, catchClause, finalizer }) {
|
||||
return reducer.reduceTryFinallyStatement(node, { body: body(), catchClause: catchClause == null ? null : catchClause(), finalizer: finalizer() });
|
||||
},
|
||||
|
||||
reduceUnaryExpression(node, { operand }) {
|
||||
return reducer.reduceUnaryExpression(node, { operand: operand() });
|
||||
},
|
||||
|
||||
reduceUpdateExpression(node, { operand }) {
|
||||
return reducer.reduceUpdateExpression(node, { operand: operand() });
|
||||
},
|
||||
|
||||
reduceVariableDeclaration(node, { declarators }) {
|
||||
return reducer.reduceVariableDeclaration(node, { declarators: declarators.map(n => n()) });
|
||||
},
|
||||
|
||||
reduceVariableDeclarationStatement(node, { declaration }) {
|
||||
return reducer.reduceVariableDeclarationStatement(node, { declaration: declaration() });
|
||||
},
|
||||
|
||||
reduceVariableDeclarator(node, { binding, init }) {
|
||||
return reducer.reduceVariableDeclarator(node, { binding: binding(), init: init == null ? null : init() });
|
||||
},
|
||||
|
||||
reduceWhileStatement(node, { test, body }) {
|
||||
return reducer.reduceWhileStatement(node, { test: test(), body: body() });
|
||||
},
|
||||
|
||||
reduceWithStatement(node, { object, body }) {
|
||||
return reducer.reduceWithStatement(node, { object: object(), body: body() });
|
||||
},
|
||||
|
||||
reduceYieldExpression(node, { expression }) {
|
||||
return reducer.reduceYieldExpression(node, { expression: expression == null ? null : expression() });
|
||||
},
|
||||
|
||||
reduceYieldGeneratorExpression(node, { expression }) {
|
||||
return reducer.reduceYieldGeneratorExpression(node, { expression: expression() });
|
||||
},
|
||||
};
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "shift-reducer",
|
||||
"version": "7.0.0",
|
||||
"description": "reducer for the Shift AST format",
|
||||
"author": "Shape Security",
|
||||
"homepage": "https://github.com/shapesecurity/shift-reducer-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shapesecurity/shift-reducer-js.git"
|
||||
},
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"gen",
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --inline-diffs --check-leaks --ui tdd --reporter dot test",
|
||||
"build": "mkdir -p gen && (for i in scripts/build/*; do node $i; done)",
|
||||
"prepare": "rm -rf gen/*.js && npm run build",
|
||||
"lint": "eslint src gen test examples"
|
||||
},
|
||||
"dependencies": {
|
||||
"shift-ast": "7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "5.6.1",
|
||||
"everything.js": "^1.0.3",
|
||||
"mocha": "^8.1.3",
|
||||
"shift-parser": "7.0.0",
|
||||
"shift-spec": "2019.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"Shift",
|
||||
"AST",
|
||||
"reducer",
|
||||
"reduce",
|
||||
"reducible",
|
||||
"monoidal",
|
||||
"monoid",
|
||||
"fold",
|
||||
"summary",
|
||||
"summarise",
|
||||
"abstract",
|
||||
"syntax",
|
||||
"tree"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/shapesecurity/shift-reducer-js/issues"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const reduce = require('../gen/director.js');
|
||||
const thunkedReduce = require('../gen/thunked-director.js');
|
||||
const thunkify = require('../gen/thunkify.js');
|
||||
const thunkifyClass = require('../gen/thunkify-class.js');
|
||||
const memoize = require('../gen/memoize.js');
|
||||
const CloneReducer = require('../gen/clone-reducer.js');
|
||||
const LazyCloneReducer = require('../gen/lazy-clone-reducer.js');
|
||||
const MonoidalReducer = require('../gen/monoidal-reducer.js');
|
||||
const ThunkedMonoidalReducer = require('../gen/thunked-monoidal-reducer.js');
|
||||
const adapt = require('../gen/adapt.js');
|
||||
const { PlusReducer, ThunkedPlusReducer, ConcatReducer, ThunkedConcatReducer, AndReducer, ThunkedAndReducer, OrReducer, ThunkedOrReducer } = require('./reducers.js');
|
||||
|
||||
module.exports = {
|
||||
default: reduce,
|
||||
reduce,
|
||||
thunkedReduce,
|
||||
thunkify,
|
||||
thunkifyClass,
|
||||
memoize,
|
||||
CloneReducer,
|
||||
LazyCloneReducer,
|
||||
MonoidalReducer,
|
||||
ThunkedMonoidalReducer,
|
||||
adapt,
|
||||
PlusReducer,
|
||||
ThunkedPlusReducer,
|
||||
ConcatReducer,
|
||||
ThunkedConcatReducer,
|
||||
AndReducer,
|
||||
ThunkedAndReducer,
|
||||
OrReducer,
|
||||
ThunkedOrReducer,
|
||||
};
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const MonoidalReducer = require('../gen/monoidal-reducer.js');
|
||||
const ThunkedMonoidalReducer = require('../gen/thunked-monoidal-reducer.js');
|
||||
|
||||
const PlusMonoid = {
|
||||
empty: () => 0,
|
||||
concat: (a, b) => a + b,
|
||||
};
|
||||
|
||||
const ConcatMonoid = {
|
||||
empty: () => [],
|
||||
concat: (a, b) => a.concat(b),
|
||||
};
|
||||
|
||||
const AndMonoid = {
|
||||
empty: () => true,
|
||||
concat: (a, b) => a && b,
|
||||
concatThunk: (a, b) => a && b(),
|
||||
};
|
||||
|
||||
const OrMonoid = {
|
||||
empty: () => false,
|
||||
concat: (a, b) => a || b,
|
||||
concatThunk: (a, b) => a || b(),
|
||||
};
|
||||
|
||||
|
||||
exports.PlusReducer = class PlusReducer extends MonoidalReducer {
|
||||
constructor() {
|
||||
super(PlusMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThunkedPlusReducer = class ThunkedPlusReducer extends ThunkedMonoidalReducer {
|
||||
constructor() {
|
||||
super(PlusMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ConcatReducer = class ConcatReducer extends MonoidalReducer {
|
||||
constructor() {
|
||||
super(ConcatMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThunkedConcatReducer = class ThunkedConcatReducer extends ThunkedMonoidalReducer {
|
||||
constructor() {
|
||||
super(ConcatMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.AndReducer = class AndReducer extends MonoidalReducer {
|
||||
constructor() {
|
||||
super(AndMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThunkedAndReducer = class ThunkedAndReducer extends ThunkedMonoidalReducer {
|
||||
constructor() {
|
||||
super(AndMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.OrReducer = class OrReducer extends MonoidalReducer {
|
||||
constructor() {
|
||||
super(OrMonoid);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ThunkedOrReducer = class ThunkedOrReducer extends ThunkedMonoidalReducer {
|
||||
constructor() {
|
||||
super(OrMonoid);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,58 @@
|
|||
Shift Regexp Acceptor
|
||||
=============
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This module provides a ECMA-262 regular expression [acceptor](https://en.wikipedia.org/wiki/Finite-state_machine#Acceptors_(recognizers)) for validation of regular expression literals for [ECMAScript 2016](https://www.ecma-international.org/ecma-262/9.0/#sec-regexp-regular-expression-objects), [Annex B](https://www.ecma-international.org/ecma-262/9.0/#sec-regular-expressions-patterns).
|
||||
|
||||
## Status
|
||||
|
||||
[Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install shift-regexp-acceptor
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import acceptRegex from 'shift-regexp-acceptor';
|
||||
|
||||
let isAccepted = acceptRegex('[a-z]+' /* source */); // unicode is assumed
|
||||
|
||||
let isAccepted = acceptRegex('[a-z]+' /* source */, { unicode: true }; // unicode mode enabled
|
||||
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
* Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
|
||||
* Fork this repo, and clone the forked repo.
|
||||
* Install dependencies with `npm install`.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Create a feature branch. Make your changes. Add tests.
|
||||
* Build and test in your environment with `npm run build && npm test`.
|
||||
* Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
|
||||
* Open a Pull Request on Github.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2018 Shape Security, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"name": "shift-regexp-acceptor",
|
||||
"version": "3.0.0",
|
||||
"description": "Regexp acceptor for ECMAScript 2018",
|
||||
"author": "Shape Security",
|
||||
"homepage": "https://github.com/shapesecurity/shift-regexp-acceptor-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shapesecurity/shift-regexp-acceptor-js.git"
|
||||
},
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "echo nothing to do",
|
||||
"test": "mocha --inline-diffs --check-leaks --ui tdd --reporter dot test && npm run lint",
|
||||
"lint": "eslint src test"
|
||||
},
|
||||
"dependencies": {
|
||||
"unicode-match-property-value-ecmascript": "1.0.2",
|
||||
"unicode-match-property-ecmascript": "1.0.4",
|
||||
"unicode-property-aliases-ecmascript": "1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "5.6.1",
|
||||
"mocha": "^8.1.3"
|
||||
},
|
||||
"keywords": [
|
||||
"Shift",
|
||||
"regex",
|
||||
"accept",
|
||||
"acceptor",
|
||||
"regular expression"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/shapesecurity/shift-regexp-acceptor-js/issues"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
}
|
|
@ -0,0 +1,754 @@
|
|||
/**
|
||||
* Copyright 2018 Shape Security, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable no-use-before-define */
|
||||
|
||||
const matchPropertyValue = require('unicode-match-property-value-ecmascript');
|
||||
|
||||
const matchPropertyValueMappings = require('unicode-match-property-value-ecmascript/data/mappings');
|
||||
|
||||
const matchProperty = require('unicode-match-property-ecmascript');
|
||||
|
||||
const propertyAliases = require('unicode-property-aliases-ecmascript');
|
||||
|
||||
const { idContinueBool, idContinueLargeRegex, idStartBool, idStartLargeRegex } = require('./unicode');
|
||||
|
||||
const catchIsFalse = predicate => {
|
||||
try {
|
||||
return !!predicate();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const syntaxCharacters = '^$\\.*+?()[]{}|'.split('');
|
||||
const extendedSyntaxCharacters = '^$\\.*+?()[|'.split('');
|
||||
|
||||
const controlEscapeCharacters = 'fnrtv'.split('');
|
||||
const controlEscapeCharacterValues = { 'f': '\f'.charCodeAt(0), 'n': '\n'.charCodeAt(0), 'r': '\r'.charCodeAt(0), 't': '\t'.charCodeAt(0), 'v': '\v'.charCodeAt(0) };
|
||||
|
||||
const controlCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||
const hexDigits = '0123456789abcdefABCDEF'.split('');
|
||||
const decimalDigits = '0123456789'.split('');
|
||||
const octalDigits = '01234567'.split('');
|
||||
|
||||
const INVALID_NAMED_BACKREFERENCE_SENTINEL = {};
|
||||
|
||||
function isIdentifierStart(ch) {
|
||||
return ch < 128 ? idStartBool[ch] : idStartLargeRegex.test(String.fromCodePoint(ch));
|
||||
}
|
||||
|
||||
function isIdentifierPart(ch) {
|
||||
return ch < 128 ? idContinueBool[ch] : idContinueLargeRegex.test(String.fromCodePoint(ch));
|
||||
}
|
||||
|
||||
class PatternAcceptorState {
|
||||
constructor(pattern, unicode) {
|
||||
this.pattern = pattern;
|
||||
this.unicode = unicode;
|
||||
this.index = 0;
|
||||
this.largestBackreference = 0;
|
||||
this.backreferenceNames = [];
|
||||
this.groupingNames = [];
|
||||
this.capturingGroups = 0;
|
||||
}
|
||||
|
||||
empty() {
|
||||
return this.index >= this.pattern.length;
|
||||
}
|
||||
|
||||
backreference(ref) {
|
||||
if (ref > this.largestBackreference) {
|
||||
this.largestBackreference = ref;
|
||||
}
|
||||
}
|
||||
|
||||
nextCodePoint() {
|
||||
if (this.empty()) {
|
||||
return null;
|
||||
}
|
||||
if (this.unicode) {
|
||||
return String.fromCodePoint(this.pattern.codePointAt(this.index));
|
||||
}
|
||||
return this.pattern.charAt(this.index);
|
||||
}
|
||||
|
||||
skipCodePoint() {
|
||||
this.index += this.nextCodePoint().length;
|
||||
}
|
||||
|
||||
eat(str) {
|
||||
if (this.index + str.length > this.pattern.length || this.pattern.slice(this.index, this.index + str.length) !== str) {
|
||||
return false;
|
||||
}
|
||||
this.index += str.length;
|
||||
return true;
|
||||
}
|
||||
|
||||
eatIdentifierCodePoint() {
|
||||
let characterValue;
|
||||
let originalIndex = this.index;
|
||||
let character;
|
||||
if (this.match('\\u')) {
|
||||
this.skipCodePoint();
|
||||
characterValue = acceptUnicodeEscape(this);
|
||||
if (!characterValue.matched) {
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
characterValue = characterValue.value;
|
||||
character = String.fromCodePoint(characterValue);
|
||||
} else {
|
||||
character = this.nextCodePoint();
|
||||
if (character == null) {
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
this.index += character.length;
|
||||
characterValue = character.codePointAt(0);
|
||||
}
|
||||
return { character, characterValue };
|
||||
}
|
||||
|
||||
eatIdentifierStart() {
|
||||
let originalIndex = this.index;
|
||||
let codePoint = this.eatIdentifierCodePoint();
|
||||
if (codePoint === null) {
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
if (codePoint.character === '_' || codePoint.character === '$' || isIdentifierStart(codePoint.characterValue)) {
|
||||
return codePoint.character;
|
||||
}
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
|
||||
eatIdentifierPart() {
|
||||
let originalIndex = this.index;
|
||||
let codePoint = this.eatIdentifierCodePoint();
|
||||
if (codePoint === null) {
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
// ZWNJ / ZWJ
|
||||
if (codePoint.character === '\u200C' || codePoint.character === '\u200D' || codePoint.character === '$' || isIdentifierPart(codePoint.characterValue)) {
|
||||
return codePoint.character;
|
||||
}
|
||||
this.index = originalIndex;
|
||||
return null;
|
||||
}
|
||||
|
||||
eatAny(...strs) {
|
||||
for (let str of strs) {
|
||||
if (this.eat(str)) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
match(str) {
|
||||
return this.index + str.length <= this.pattern.length && this.pattern.slice(this.index, this.index + str.length) === str;
|
||||
}
|
||||
|
||||
matchAny(...strs) {
|
||||
for (let str of strs) {
|
||||
if (this.match(str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
eatNaturalNumber() {
|
||||
let characters = [];
|
||||
let eatNumber = () => {
|
||||
for (let str of decimalDigits) {
|
||||
if (this.eat(str)) {
|
||||
characters.push(str);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
while (eatNumber());
|
||||
return characters.length === 0 ? null : characters.join('');
|
||||
}
|
||||
}
|
||||
|
||||
// acceptRegex
|
||||
module.exports = (pattern, { unicode = false } = {}) => {
|
||||
let state = new PatternAcceptorState(pattern, unicode);
|
||||
let accepted = acceptDisjunction(state);
|
||||
if (accepted.matched) {
|
||||
if (state.unicode) {
|
||||
if (state.largestBackreference > state.capturingGroups) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (state.groupingNames.length > 0 || state.unicode) {
|
||||
for (let backreferenceName of state.backreferenceNames) {
|
||||
if (state.groupingNames.indexOf(backreferenceName) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return accepted.matched;
|
||||
};
|
||||
|
||||
const backtrackOnFailure = func => state => {
|
||||
let savedIndex = state.index;
|
||||
let oldBackreference = state.largestBackreference;
|
||||
let oldCapturingGroups = state.capturingGroups;
|
||||
let val = func(state);
|
||||
if (!val.matched) {
|
||||
state.index = savedIndex;
|
||||
state.largestBackreference = oldBackreference;
|
||||
state.capturingGroups = oldCapturingGroups;
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
const acceptUnicodeEscape = backtrackOnFailure(state => {
|
||||
if (!state.eat('u')) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (state.unicode && state.eat('{')) {
|
||||
let digits = [];
|
||||
while (!state.eat('}')) {
|
||||
let digit = state.eatAny(...hexDigits);
|
||||
if (digit === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
digits.push(digit);
|
||||
}
|
||||
let value = parseInt(digits.join(''), 16);
|
||||
return value > 0x10FFFF ? { matched: false } : { matched: true, value };
|
||||
}
|
||||
let digits = [0, 0, 0, 0].map(() => state.eatAny(...hexDigits));
|
||||
if (digits.some(digit => digit === null)) {
|
||||
return { matched: false };
|
||||
}
|
||||
let value = parseInt(digits.join(''), 16);
|
||||
if (state.unicode && value >= 0xD800 && value <= 0xDBFF) {
|
||||
let surrogatePairValue = backtrackOnFailure(subState => {
|
||||
if (!subState.eat('\\u')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let digits2 = [0, 0, 0, 0].map(() => subState.eatAny(...hexDigits));
|
||||
if (digits2.some(digit => digit === null)) {
|
||||
return { matched: false };
|
||||
}
|
||||
let value2 = parseInt(digits2.join(''), 16);
|
||||
if (value2 < 0xDC00 || value2 >= 0xE000) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: 0x10000 + ((value & 0x03FF) << 10) + (value2 & 0x03FF) };
|
||||
})(state);
|
||||
if (surrogatePairValue.matched) {
|
||||
return surrogatePairValue;
|
||||
}
|
||||
}
|
||||
return { matched: true, value };
|
||||
});
|
||||
|
||||
const acceptDisjunction = (state, terminator) => {
|
||||
do {
|
||||
if (terminator !== void 0 && state.eat(terminator)) {
|
||||
return { matched: true };
|
||||
} else if (state.match('|')) {
|
||||
continue;
|
||||
}
|
||||
if (!acceptAlternative(state, terminator).matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
} while (state.eat('|'));
|
||||
return { matched: terminator === void 0 || !!state.eat(terminator) };
|
||||
};
|
||||
|
||||
const acceptAlternative = (state, terminator) => {
|
||||
while (!state.match('|') && !state.empty() && (terminator === void 0 || !state.match(terminator))) {
|
||||
if (!acceptTerm(state).matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
}
|
||||
return { matched: true };
|
||||
};
|
||||
|
||||
const anyOf = (...acceptors) => state => {
|
||||
for (let predicate of acceptors) {
|
||||
let value = predicate(state);
|
||||
if (value.matched) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return { matched: false };
|
||||
};
|
||||
|
||||
const acceptTerm = state => {
|
||||
// non-quantified references are rolled into quantified accepts to improve performance significantly.
|
||||
if (state.unicode) {
|
||||
return anyOf(acceptAssertion, acceptQuantified(acceptAtom))(state);
|
||||
}
|
||||
return anyOf(acceptQuantified(acceptQuantifiableAssertion),
|
||||
acceptAssertion,
|
||||
acceptQuantified(acceptAtom))(state);
|
||||
};
|
||||
|
||||
const acceptLabeledGroup = predicate => backtrackOnFailure(state => {
|
||||
if (!state.eat('(')) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (predicate(state)) {
|
||||
return acceptDisjunction(state, ')');
|
||||
}
|
||||
return { matched: false };
|
||||
});
|
||||
|
||||
const acceptQuantifiableAssertion = acceptLabeledGroup(state => !!state.eatAny('?=', '?!'));
|
||||
|
||||
const acceptAssertion = state => {
|
||||
if (state.eatAny('^', '$', '\\b', '\\B')) {
|
||||
return { matched: true };
|
||||
}
|
||||
return acceptLabeledGroup(subState => subState.unicode ? !!subState.eatAny('?=', '?!', '?<=', '?<!') : !!subState.eatAny('?<=', '?<!'))(state);
|
||||
};
|
||||
|
||||
const acceptDecimal = state => {
|
||||
return { matched: state.eatNaturalNumber() !== null };
|
||||
};
|
||||
|
||||
const acceptQuantified = acceptor => backtrackOnFailure(state => {
|
||||
if (!acceptor(state).matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (state.match('{')) {
|
||||
let value = backtrackOnFailure(subState => {
|
||||
subState.eat('{');
|
||||
let num1 = subState.eatNaturalNumber();
|
||||
if (num1 === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (subState.eat(',') && subState.matchAny(...decimalDigits)) {
|
||||
let num2 = subState.eatNaturalNumber();
|
||||
if (num2 === null || parseInt(num1) > parseInt(num2)) {
|
||||
return { matched: false };
|
||||
}
|
||||
}
|
||||
if (!subState.eat('}')) {
|
||||
return { matched: false };
|
||||
}
|
||||
subState.eat('?');
|
||||
return { matched: true };
|
||||
})(state);
|
||||
if (!value.matched) {
|
||||
return { matched: !state.unicode };
|
||||
}
|
||||
return value;
|
||||
} else if (state.eatAny('*', '+', '?')) {
|
||||
state.eat('?');
|
||||
}
|
||||
return { matched: true };
|
||||
});
|
||||
|
||||
const acceptCharacterExcept = characters => state => {
|
||||
let nextCodePoint = state.nextCodePoint();
|
||||
if (nextCodePoint === null || characters.indexOf(nextCodePoint) !== -1) {
|
||||
return { matched: false };
|
||||
}
|
||||
state.skipCodePoint();
|
||||
return { matched: true };
|
||||
};
|
||||
|
||||
const acceptPatternCharacter = acceptCharacterExcept(syntaxCharacters);
|
||||
|
||||
const acceptExtendedPatternCharacter = acceptCharacterExcept(extendedSyntaxCharacters);
|
||||
|
||||
const acceptInvalidBracedQuantifier = state => {
|
||||
return backtrackOnFailure(subState => {
|
||||
return { matched: !!(subState.eat('{') && acceptDecimal(subState).matched && (!subState.eat(',') || subState.match('}') || acceptDecimal(subState).matched) && subState.eat('}')) };
|
||||
})(state);
|
||||
};
|
||||
|
||||
const acceptAtom = state => {
|
||||
if (state.unicode) {
|
||||
return anyOf(acceptPatternCharacter,
|
||||
subState => ({ matched: !!subState.eat('.') }),
|
||||
backtrackOnFailure(subState => subState.eat('\\') ? acceptAtomEscape(subState) : { matched: false }),
|
||||
acceptCharacterClass,
|
||||
acceptLabeledGroup(subState => subState.eat('?:')),
|
||||
acceptGrouping)(state);
|
||||
}
|
||||
let matched = anyOf(
|
||||
subState => ({ matched: !!subState.eat('.') }),
|
||||
backtrackOnFailure(subState => subState.eat('\\') ? acceptAtomEscape(subState) : { matched: false }),
|
||||
backtrackOnFailure(subState => ({ matched: subState.eat('\\') && subState.match('c') })),
|
||||
acceptCharacterClass,
|
||||
acceptLabeledGroup(subState => subState.eat('?:')),
|
||||
acceptGrouping)(state);
|
||||
if (!matched.matched && acceptInvalidBracedQuantifier(state).matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
return matched.matched ? matched : acceptExtendedPatternCharacter(state);
|
||||
|
||||
};
|
||||
|
||||
const acceptGrouping = backtrackOnFailure(state => {
|
||||
if (!state.eat('(')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let groupName = backtrackOnFailure(subState => {
|
||||
if (!state.eat('?')) {
|
||||
return { matched: false };
|
||||
}
|
||||
return acceptGroupName(subState);
|
||||
})(state);
|
||||
if (!acceptDisjunction(state, ')').matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (groupName.matched) {
|
||||
if (state.groupingNames.indexOf(groupName.data) !== -1) {
|
||||
return { matched: false };
|
||||
}
|
||||
state.groupingNames.push(groupName.data);
|
||||
}
|
||||
state.capturingGroups++;
|
||||
return { matched: true };
|
||||
});
|
||||
|
||||
const acceptDecimalEscape = backtrackOnFailure(state => {
|
||||
let firstDecimal = state.eatAny(...decimalDigits);
|
||||
if (firstDecimal === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (firstDecimal === '0') {
|
||||
return { matched: true };
|
||||
}
|
||||
// we also accept octal escapes here, but it is impossible to tell if it is a octal escape until all parsing is complete.
|
||||
// octal escapes are handled in acceptCharacterEscape for classes
|
||||
state.backreference(parseInt(firstDecimal + (state.eatNaturalNumber() || '')));
|
||||
return { matched: true };
|
||||
});
|
||||
|
||||
const acceptCharacterClassEscape = state => {
|
||||
if (state.eatAny('d', 'D', 's', 'S', 'w', 'W')) {
|
||||
return { matched: true };
|
||||
}
|
||||
if (state.unicode) {
|
||||
return backtrackOnFailure(subState => {
|
||||
if (!subState.eat('p{') && !subState.eat('P{')) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (!acceptUnicodePropertyValueExpression(subState).matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: !!subState.eat('}') };
|
||||
})(state);
|
||||
}
|
||||
return { matched: false };
|
||||
};
|
||||
|
||||
const acceptUnicodePropertyName = state => {
|
||||
let characters = [];
|
||||
let character;
|
||||
while (character = state.eatAny(...controlCharacters, '_')) { // eslint-disable-line no-cond-assign
|
||||
characters.push(character);
|
||||
}
|
||||
return { matched: characters.length > 0, data: characters.join('') };
|
||||
};
|
||||
|
||||
const acceptUnicodePropertyValue = state => {
|
||||
let characters = [];
|
||||
let character;
|
||||
while (character = state.eatAny(...controlCharacters, ...decimalDigits, '_')) { // eslint-disable-line no-cond-assign
|
||||
characters.push(character);
|
||||
}
|
||||
return { matched: characters.length > 0, data: characters.join('') };
|
||||
};
|
||||
|
||||
// excluding nonbinary properties from mathias' list
|
||||
// https://www.ecma-international.org/ecma-262/9.0/index.html#table-nonbinary-unicode-properties
|
||||
const illegalLoneUnicodePropertyNames = [
|
||||
'General_Category',
|
||||
'Script',
|
||||
'Script_Extensions',
|
||||
'scx',
|
||||
'sc',
|
||||
'gc',
|
||||
];
|
||||
|
||||
const generalCategoryValues = matchPropertyValueMappings.get('General_Category');
|
||||
|
||||
const acceptLoneUnicodePropertyNameOrValue = state => {
|
||||
let loneValue = acceptUnicodePropertyValue(state);
|
||||
if (!loneValue.matched || illegalLoneUnicodePropertyNames.includes(loneValue.data)) {
|
||||
return { matched: false };
|
||||
}
|
||||
|
||||
return { matched: catchIsFalse(() => matchProperty(loneValue.data)) || generalCategoryValues.get(loneValue.data) != null };
|
||||
};
|
||||
|
||||
const acceptUnicodePropertyValueExpression = state =>
|
||||
anyOf(backtrackOnFailure(subState => {
|
||||
let name = acceptUnicodePropertyName(subState);
|
||||
if (!name.matched || !subState.eat('=')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let value = acceptUnicodePropertyValue(subState);
|
||||
if (!value.matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: catchIsFalse(() => matchPropertyValue(propertyAliases.get(name.data) || name.data, value.data)) };
|
||||
}),
|
||||
backtrackOnFailure(acceptLoneUnicodePropertyNameOrValue))(state);
|
||||
|
||||
const acceptCharacterEscape = anyOf(
|
||||
state => {
|
||||
let eaten = state.eatAny(...controlEscapeCharacters);
|
||||
if (eaten === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: controlEscapeCharacterValues[eaten] };
|
||||
},
|
||||
backtrackOnFailure(state => {
|
||||
if (!state.eat('c')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let character = state.eatAny(...controlCharacters);
|
||||
if (character === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: character.charCodeAt(0) % 32 };
|
||||
}),
|
||||
backtrackOnFailure(state => {
|
||||
if (!state.eat('0') || state.eatAny(...decimalDigits)) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: 0 };
|
||||
}),
|
||||
backtrackOnFailure(state => {
|
||||
if (!state.eat('x')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let digits = [0, 0].map(() => state.eatAny(...hexDigits));
|
||||
if (digits.some(value => value === null)) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: parseInt(digits.join(''), 16) };
|
||||
}),
|
||||
acceptUnicodeEscape,
|
||||
backtrackOnFailure(state => {
|
||||
if (state.unicode) {
|
||||
return { matched: false };
|
||||
}
|
||||
let octal1 = state.eatAny(...octalDigits);
|
||||
if (octal1 === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
let octal1Value = parseInt(octal1, 8);
|
||||
if (octalDigits.indexOf(state.nextCodePoint()) === -1) {
|
||||
return { matched: true, value: octal1Value };
|
||||
}
|
||||
let octal2 = state.eatAny(...octalDigits);
|
||||
let octal2Value = parseInt(octal2, 8);
|
||||
if (octal1Value < 4) {
|
||||
if (octalDigits.indexOf(state.nextCodePoint()) === -1) {
|
||||
return { matched: true, value: octal1Value << 3 | octal2Value };
|
||||
}
|
||||
let octal3 = state.eatAny(...octalDigits);
|
||||
let octal3Value = parseInt(octal3, 8);
|
||||
return { matched: true, value: octal1Value << 6 | octal2Value << 3 | octal3Value };
|
||||
}
|
||||
return { matched: true, value: octal1Value << 3 | octal2Value };
|
||||
}),
|
||||
backtrackOnFailure(state => {
|
||||
if (!state.unicode) {
|
||||
return { matched: false };
|
||||
}
|
||||
let value = state.eatAny(...syntaxCharacters);
|
||||
if (value === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: value.charCodeAt(0) };
|
||||
}),
|
||||
state => {
|
||||
if (!state.unicode || !state.eat('/')) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: '/'.charCodeAt(0) };
|
||||
},
|
||||
backtrackOnFailure(state => {
|
||||
if (state.unicode) {
|
||||
return { matched: false };
|
||||
}
|
||||
let next = state.nextCodePoint();
|
||||
if (next !== null && next !== 'c' && next !== 'k') {
|
||||
state.skipCodePoint();
|
||||
return { matched: true, value: next.codePointAt(0) };
|
||||
}
|
||||
return { matched: false };
|
||||
})
|
||||
);
|
||||
|
||||
const acceptGroupNameBackreference = backtrackOnFailure(state => {
|
||||
if (!state.eat('k')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let name = acceptGroupName(state);
|
||||
if (!name.matched) {
|
||||
state.backreferenceNames.push(INVALID_NAMED_BACKREFERENCE_SENTINEL);
|
||||
return { matched: true };
|
||||
}
|
||||
state.backreferenceNames.push(name.data);
|
||||
return { matched: true };
|
||||
});
|
||||
|
||||
const acceptGroupName = backtrackOnFailure(state => {
|
||||
if (!state.eat('<')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let characters = [];
|
||||
let start = state.eatIdentifierStart();
|
||||
if (!start) {
|
||||
return { matched: false };
|
||||
}
|
||||
characters.push(start);
|
||||
let part;
|
||||
while (part = state.eatIdentifierPart()) { // eslint-disable-line no-cond-assign
|
||||
characters.push(part);
|
||||
}
|
||||
if (!state.eat('>')) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: characters.length > 0, data: characters.join('') };
|
||||
});
|
||||
|
||||
const acceptAtomEscape = anyOf(
|
||||
acceptDecimalEscape,
|
||||
acceptCharacterClassEscape,
|
||||
acceptCharacterEscape,
|
||||
acceptGroupNameBackreference
|
||||
);
|
||||
|
||||
const acceptCharacterClass = backtrackOnFailure(state => {
|
||||
if (!state.eat('[')) {
|
||||
return { matched: false };
|
||||
}
|
||||
state.eat('^');
|
||||
|
||||
const acceptClassEscape = anyOf(
|
||||
subState => {
|
||||
return { matched: !!subState.eat('b'), value: 0x0008 };
|
||||
},
|
||||
subState => {
|
||||
return { matched: subState.unicode && !!subState.eat('-'), value: '-'.charCodeAt(0) };
|
||||
},
|
||||
backtrackOnFailure(subState => {
|
||||
if (subState.unicode || !subState.eat('c')) {
|
||||
return { matched: false };
|
||||
}
|
||||
let character = subState.eatAny(...decimalDigits, '_');
|
||||
if (character === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
return { matched: true, value: character.charCodeAt(0) % 32 };
|
||||
}),
|
||||
acceptCharacterClassEscape,
|
||||
acceptCharacterEscape,
|
||||
// We special-case `\k` because `acceptCharacterEscape` rejects `\k` unconditionally,
|
||||
// deferring `\k` to acceptGroupNameBackreference, which is not called here.
|
||||
// See also https://github.com/tc39/ecma262/issues/2037. This code takes the route of
|
||||
// making it unconditionally legal, rather than legal only in the absence of a group name.
|
||||
subState => {
|
||||
return { matched: !subState.unicode && !!subState.eat('k'), value: 107 };
|
||||
}
|
||||
);
|
||||
|
||||
const acceptClassAtomNoDash = localState => {
|
||||
let nextCodePoint = localState.nextCodePoint();
|
||||
if (nextCodePoint === ']' || nextCodePoint === '-' || nextCodePoint === null) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (nextCodePoint !== '\\') {
|
||||
localState.skipCodePoint();
|
||||
return { matched: true, value: nextCodePoint.codePointAt(0) };
|
||||
}
|
||||
localState.eat('\\');
|
||||
let classEscape = acceptClassEscape(localState);
|
||||
if (!classEscape.matched && localState.nextCodePoint() === 'c' && !localState.unicode) {
|
||||
return { matched: true, value: '\\'.charCodeAt(0) };
|
||||
}
|
||||
return classEscape;
|
||||
};
|
||||
|
||||
const acceptClassAtom = localState => {
|
||||
if (localState.eat('-')) {
|
||||
return { matched: true, value: '-'.charCodeAt(0) };
|
||||
}
|
||||
return acceptClassAtomNoDash(localState);
|
||||
};
|
||||
|
||||
const finishClassRange = (localState, atom) => {
|
||||
const isUnvaluedPassedAtom = subAtom => {
|
||||
return subAtom.value === void 0 && subAtom.matched;
|
||||
};
|
||||
if (localState.eat('-')) {
|
||||
if (localState.match(']')) {
|
||||
return { matched: true };
|
||||
}
|
||||
let otherAtom = acceptClassAtom(localState);
|
||||
if (!otherAtom.matched) {
|
||||
return { matched: false };
|
||||
}
|
||||
if (localState.unicode && (isUnvaluedPassedAtom(atom) || isUnvaluedPassedAtom(otherAtom))) {
|
||||
return { matched: false };
|
||||
} else if (!(!localState.unicode && (isUnvaluedPassedAtom(atom) || isUnvaluedPassedAtom(otherAtom))) && atom.value > otherAtom.value) {
|
||||
return { matched: false };
|
||||
} else if (localState.match(']')) {
|
||||
return { matched: true };
|
||||
}
|
||||
return acceptNonEmptyClassRanges(localState);
|
||||
|
||||
}
|
||||
if (localState.match(']')) {
|
||||
return { matched: true };
|
||||
}
|
||||
return acceptNonEmptyClassRangesNoDash(localState);
|
||||
};
|
||||
|
||||
const acceptNonEmptyClassRanges = localState => {
|
||||
let atom = acceptClassAtom(localState);
|
||||
return atom.matched ? finishClassRange(localState, atom) : { matched: false };
|
||||
};
|
||||
|
||||
const acceptNonEmptyClassRangesNoDash = localState => {
|
||||
let atom = acceptClassAtomNoDash(localState);
|
||||
return atom.matched ? finishClassRange(localState, atom) : { matched: false };
|
||||
};
|
||||
|
||||
if (state.eat(']')) {
|
||||
return { matched: true };
|
||||
}
|
||||
|
||||
let value = acceptNonEmptyClassRanges(state);
|
||||
if (value.matched) {
|
||||
state.eat(']'); // cannot fail, as above will not return matched if it is not seen in advance
|
||||
}
|
||||
|
||||
return value;
|
||||
});
|
File diff suppressed because one or more lines are too long
20
node_modules/unicode-canonical-property-names-ecmascript/LICENSE-MIT.txt
generated
vendored
Normal file
20
node_modules/unicode-canonical-property-names-ecmascript/LICENSE-MIT.txt
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
node_modules/unicode-canonical-property-names-ecmascript/README.md
generated
vendored
Normal file
36
node_modules/unicode-canonical-property-names-ecmascript/README.md
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
# unicode-canonical-property-names-ecmascript [![Build status](https://travis-ci.org/mathiasbynens/unicode-canonical-property-names-ecmascript.svg?branch=master)](https://travis-ci.org/mathiasbynens/unicode-canonical-property-names-ecmascript)
|
||||
|
||||
_unicode-canonical-property-names-ecmascript_ exports the set of canonical Unicode property names that are supported in [ECMAScript RegExp property escapes](https://github.com/tc39/proposal-regexp-unicode-property-escapes).
|
||||
|
||||
## Installation
|
||||
|
||||
To use _unicode-canonical-property-names-ecmascript_, install it as a dependency via [npm](https://www.npmjs.com/):
|
||||
|
||||
```bash
|
||||
$ npm install unicode-canonical-property-names-ecmascript
|
||||
```
|
||||
|
||||
Then, `require` it:
|
||||
|
||||
```js
|
||||
const properties = require('unicode-canonical-property-names-ecmascript');
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
properties.has('ID_Start');
|
||||
// → true
|
||||
properties.has('IDS');
|
||||
// → false
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
||||
|---|
|
||||
| [Mathias Bynens](https://mathiasbynens.be/) |
|
||||
|
||||
## License
|
||||
|
||||
_unicode-canonical-property-names-ecmascript_ is available under the [MIT](https://mths.be/mit) license.
|
60
node_modules/unicode-canonical-property-names-ecmascript/index.js
generated
vendored
Executable file
60
node_modules/unicode-canonical-property-names-ecmascript/index.js
generated
vendored
Executable file
|
@ -0,0 +1,60 @@
|
|||
module.exports = new Set([
|
||||
// Non-binary properties:
|
||||
'General_Category',
|
||||
'Script',
|
||||
'Script_Extensions',
|
||||
// Binary properties:
|
||||
'Alphabetic',
|
||||
'Any',
|
||||
'ASCII',
|
||||
'ASCII_Hex_Digit',
|
||||
'Assigned',
|
||||
'Bidi_Control',
|
||||
'Bidi_Mirrored',
|
||||
'Case_Ignorable',
|
||||
'Cased',
|
||||
'Changes_When_Casefolded',
|
||||
'Changes_When_Casemapped',
|
||||
'Changes_When_Lowercased',
|
||||
'Changes_When_NFKC_Casefolded',
|
||||
'Changes_When_Titlecased',
|
||||
'Changes_When_Uppercased',
|
||||
'Dash',
|
||||
'Default_Ignorable_Code_Point',
|
||||
'Deprecated',
|
||||
'Diacritic',
|
||||
'Emoji',
|
||||
'Emoji_Component',
|
||||
'Emoji_Modifier',
|
||||
'Emoji_Modifier_Base',
|
||||
'Emoji_Presentation',
|
||||
'Extended_Pictographic',
|
||||
'Extender',
|
||||
'Grapheme_Base',
|
||||
'Grapheme_Extend',
|
||||
'Hex_Digit',
|
||||
'ID_Continue',
|
||||
'ID_Start',
|
||||
'Ideographic',
|
||||
'IDS_Binary_Operator',
|
||||
'IDS_Trinary_Operator',
|
||||
'Join_Control',
|
||||
'Logical_Order_Exception',
|
||||
'Lowercase',
|
||||
'Math',
|
||||
'Noncharacter_Code_Point',
|
||||
'Pattern_Syntax',
|
||||
'Pattern_White_Space',
|
||||
'Quotation_Mark',
|
||||
'Radical',
|
||||
'Regional_Indicator',
|
||||
'Sentence_Terminal',
|
||||
'Soft_Dotted',
|
||||
'Terminal_Punctuation',
|
||||
'Unified_Ideograph',
|
||||
'Uppercase',
|
||||
'Variation_Selector',
|
||||
'White_Space',
|
||||
'XID_Continue',
|
||||
'XID_Start'
|
||||
]);
|
34
node_modules/unicode-canonical-property-names-ecmascript/package.json
generated
vendored
Normal file
34
node_modules/unicode-canonical-property-names-ecmascript/package.json
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "unicode-canonical-property-names-ecmascript",
|
||||
"version": "1.0.4",
|
||||
"description": "The set of canonical Unicode property names supported in ECMAScript RegExp property escapes.",
|
||||
"homepage": "https://github.com/mathiasbynens/unicode-canonical-property-names-ecmascript",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE-MIT.txt",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"unicode",
|
||||
"unicode properties"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathiasbynens/unicode-canonical-property-names-ecmascript.git"
|
||||
},
|
||||
"bugs": "https://github.com/mathiasbynens/unicode-canonical-property-names-ecmascript/issues",
|
||||
"devDependencies": {
|
||||
"ava": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "ava ./tests"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,47 @@
|
|||
# unicode-match-property-ecmascript [![Build status](https://travis-ci.org/mathiasbynens/unicode-match-property-ecmascript.svg?branch=master)](https://travis-ci.org/mathiasbynens/unicode-match-property-ecmascript)
|
||||
|
||||
_unicode-match-property-ecmascript_ matches a given Unicode property or [property alias](https://github.com/mathiasbynens/unicode-property-aliases-ecmascript) to its canonical property name without applying [loose matching](https://github.com/mathiasbynens/unicode-loose-match) per the algorithm used for [RegExp Unicode property escapes in ECMAScript](https://github.com/tc39/proposal-regexp-unicode-property-escapes). Consider it a strict alternative to loose matching.
|
||||
|
||||
## Installation
|
||||
|
||||
To use _unicode-match-property-ecmascript_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
|
||||
|
||||
```bash
|
||||
$ npm install unicode-match-property-ecmascript
|
||||
```
|
||||
|
||||
Then, `require` it:
|
||||
|
||||
```js
|
||||
const matchProperty = require('unicode-match-property-ecmascript');
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This module exports a single function named `matchProperty`.
|
||||
|
||||
### `matchProperty(value)`
|
||||
|
||||
This function takes a string `value` and attempts to match it to a canonical Unicode property name. If there’s a match, it returns the canonical property name. Otherwise, it throws an exception.
|
||||
|
||||
```js
|
||||
// Find the canonical property name:
|
||||
matchProperty('sc')
|
||||
// → 'Script'
|
||||
|
||||
matchProperty('Script')
|
||||
// → 'Script'
|
||||
|
||||
matchProperty('script') // Note: incorrect casing.
|
||||
// → throws
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
||||
|---|
|
||||
| [Mathias Bynens](https://mathiasbynens.be/) |
|
||||
|
||||
## License
|
||||
|
||||
_unicode-match-property-ecmascript_ is available under the [MIT](https://mths.be/mit) license.
|
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const canonicalProperties = require('unicode-canonical-property-names-ecmascript');
|
||||
const propertyAliases = require('unicode-property-aliases-ecmascript');
|
||||
|
||||
const matchProperty = function(property) {
|
||||
if (canonicalProperties.has(property)) {
|
||||
return property;
|
||||
}
|
||||
if (propertyAliases.has(property)) {
|
||||
return propertyAliases.get(property);
|
||||
}
|
||||
throw new Error(`Unknown property: ${ property }`);
|
||||
};
|
||||
|
||||
module.exports = matchProperty;
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "unicode-match-property-ecmascript",
|
||||
"version": "1.0.4",
|
||||
"description": "Match a Unicode property or property alias to its canonical property name per the algorithm used for RegExp Unicode property escapes in ECMAScript.",
|
||||
"homepage": "https://github.com/mathiasbynens/unicode-match-property-ecmascript",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE-MIT.txt",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"unicode",
|
||||
"unicode properties",
|
||||
"unicode property aliases"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathiasbynens/unicode-match-property-ecmascript.git"
|
||||
},
|
||||
"bugs": "https://github.com/mathiasbynens/unicode-match-property-ecmascript/issues",
|
||||
"dependencies": {
|
||||
"unicode-canonical-property-names-ecmascript": "^1.0.4",
|
||||
"unicode-property-aliases-ecmascript": "^1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "ava ./tests"
|
||||
}
|
||||
}
|
20
node_modules/unicode-match-property-value-ecmascript/LICENSE-MIT.txt
generated
vendored
Normal file
20
node_modules/unicode-match-property-value-ecmascript/LICENSE-MIT.txt
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,50 @@
|
|||
# unicode-match-property-value-ecmascript [![Build status](https://travis-ci.org/mathiasbynens/unicode-match-property-value-ecmascript.svg?branch=master)](https://travis-ci.org/mathiasbynens/unicode-match-property-value-ecmascript)
|
||||
|
||||
_unicode-match-property-value-ecmascript_ matches a given Unicode property value or [property value alias](https://github.com/mathiasbynens/unicode-property-value-aliases) to its canonical property value without applying [loose matching](https://github.com/mathiasbynens/unicode-loose-match), per the algorithm used for [RegExp Unicode property escapes in ECMAScript](https://github.com/tc39/proposal-regexp-unicode-property-escapes). Consider it a strict alternative to loose matching.
|
||||
|
||||
## Installation
|
||||
|
||||
To use _unicode-match-property-value-ecmascript_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
|
||||
|
||||
```bash
|
||||
$ npm install unicode-match-property-value-ecmascript
|
||||
```
|
||||
|
||||
Then, `require` it:
|
||||
|
||||
```js
|
||||
const matchPropertyValue = require('unicode-match-property-value-ecmascript');
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This module exports a single function named `matchPropertyValue`.
|
||||
|
||||
### `matchPropertyValue(property, value)`
|
||||
|
||||
This function takes a string `property` that is a canonical/unaliased Unicode property name, and a string `value`. It attemps to match `value` to a canonical Unicode property value for the given property. If there’s a match, it returns the canonical property value. Otherwise, it throws an exception.
|
||||
|
||||
```js
|
||||
// Find the canonical property value:
|
||||
matchPropertyValue('Script_Extensions', 'Aghb')
|
||||
// → 'Caucasian_Albanian'
|
||||
|
||||
matchPropertyValue('Script_Extensions', 'Caucasian_Albanian')
|
||||
// → 'Caucasian_Albanian'
|
||||
|
||||
matchPropertyValue('script_extensions', 'Caucasian_Albanian') // Note: incorrect casing.
|
||||
// → throws
|
||||
|
||||
matchPropertyValue('Script_Extensions', 'caucasian_albanian') // Note: incorrect casing.
|
||||
// → throws
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
||||
|---|
|
||||
| [Mathias Bynens](https://mathiasbynens.be/) |
|
||||
|
||||
## License
|
||||
|
||||
_unicode-match-property-value-ecmascript_ is available under the [MIT](https://mths.be/mit) license.
|
680
node_modules/unicode-match-property-value-ecmascript/data/mappings.js
generated
vendored
Normal file
680
node_modules/unicode-match-property-value-ecmascript/data/mappings.js
generated
vendored
Normal file
|
@ -0,0 +1,680 @@
|
|||
module.exports = new Map([
|
||||
['General_Category', new Map([
|
||||
['C', 'Other'],
|
||||
['Cc', 'Control'],
|
||||
['cntrl', 'Control'],
|
||||
['Cf', 'Format'],
|
||||
['Cn', 'Unassigned'],
|
||||
['Co', 'Private_Use'],
|
||||
['Cs', 'Surrogate'],
|
||||
['L', 'Letter'],
|
||||
['LC', 'Cased_Letter'],
|
||||
['Ll', 'Lowercase_Letter'],
|
||||
['Lm', 'Modifier_Letter'],
|
||||
['Lo', 'Other_Letter'],
|
||||
['Lt', 'Titlecase_Letter'],
|
||||
['Lu', 'Uppercase_Letter'],
|
||||
['M', 'Mark'],
|
||||
['Combining_Mark', 'Mark'],
|
||||
['Mc', 'Spacing_Mark'],
|
||||
['Me', 'Enclosing_Mark'],
|
||||
['Mn', 'Nonspacing_Mark'],
|
||||
['N', 'Number'],
|
||||
['Nd', 'Decimal_Number'],
|
||||
['digit', 'Decimal_Number'],
|
||||
['Nl', 'Letter_Number'],
|
||||
['No', 'Other_Number'],
|
||||
['P', 'Punctuation'],
|
||||
['punct', 'Punctuation'],
|
||||
['Pc', 'Connector_Punctuation'],
|
||||
['Pd', 'Dash_Punctuation'],
|
||||
['Pe', 'Close_Punctuation'],
|
||||
['Pf', 'Final_Punctuation'],
|
||||
['Pi', 'Initial_Punctuation'],
|
||||
['Po', 'Other_Punctuation'],
|
||||
['Ps', 'Open_Punctuation'],
|
||||
['S', 'Symbol'],
|
||||
['Sc', 'Currency_Symbol'],
|
||||
['Sk', 'Modifier_Symbol'],
|
||||
['Sm', 'Math_Symbol'],
|
||||
['So', 'Other_Symbol'],
|
||||
['Z', 'Separator'],
|
||||
['Zl', 'Line_Separator'],
|
||||
['Zp', 'Paragraph_Separator'],
|
||||
['Zs', 'Space_Separator'],
|
||||
['Other', 'Other'],
|
||||
['Control', 'Control'],
|
||||
['Format', 'Format'],
|
||||
['Unassigned', 'Unassigned'],
|
||||
['Private_Use', 'Private_Use'],
|
||||
['Surrogate', 'Surrogate'],
|
||||
['Letter', 'Letter'],
|
||||
['Cased_Letter', 'Cased_Letter'],
|
||||
['Lowercase_Letter', 'Lowercase_Letter'],
|
||||
['Modifier_Letter', 'Modifier_Letter'],
|
||||
['Other_Letter', 'Other_Letter'],
|
||||
['Titlecase_Letter', 'Titlecase_Letter'],
|
||||
['Uppercase_Letter', 'Uppercase_Letter'],
|
||||
['Mark', 'Mark'],
|
||||
['Spacing_Mark', 'Spacing_Mark'],
|
||||
['Enclosing_Mark', 'Enclosing_Mark'],
|
||||
['Nonspacing_Mark', 'Nonspacing_Mark'],
|
||||
['Number', 'Number'],
|
||||
['Decimal_Number', 'Decimal_Number'],
|
||||
['Letter_Number', 'Letter_Number'],
|
||||
['Other_Number', 'Other_Number'],
|
||||
['Punctuation', 'Punctuation'],
|
||||
['Connector_Punctuation', 'Connector_Punctuation'],
|
||||
['Dash_Punctuation', 'Dash_Punctuation'],
|
||||
['Close_Punctuation', 'Close_Punctuation'],
|
||||
['Final_Punctuation', 'Final_Punctuation'],
|
||||
['Initial_Punctuation', 'Initial_Punctuation'],
|
||||
['Other_Punctuation', 'Other_Punctuation'],
|
||||
['Open_Punctuation', 'Open_Punctuation'],
|
||||
['Symbol', 'Symbol'],
|
||||
['Currency_Symbol', 'Currency_Symbol'],
|
||||
['Modifier_Symbol', 'Modifier_Symbol'],
|
||||
['Math_Symbol', 'Math_Symbol'],
|
||||
['Other_Symbol', 'Other_Symbol'],
|
||||
['Separator', 'Separator'],
|
||||
['Line_Separator', 'Line_Separator'],
|
||||
['Paragraph_Separator', 'Paragraph_Separator'],
|
||||
['Space_Separator', 'Space_Separator']
|
||||
])],
|
||||
['Script', new Map([
|
||||
['Adlm', 'Adlam'],
|
||||
['Aghb', 'Caucasian_Albanian'],
|
||||
['Ahom', 'Ahom'],
|
||||
['Arab', 'Arabic'],
|
||||
['Armi', 'Imperial_Aramaic'],
|
||||
['Armn', 'Armenian'],
|
||||
['Avst', 'Avestan'],
|
||||
['Bali', 'Balinese'],
|
||||
['Bamu', 'Bamum'],
|
||||
['Bass', 'Bassa_Vah'],
|
||||
['Batk', 'Batak'],
|
||||
['Beng', 'Bengali'],
|
||||
['Bhks', 'Bhaiksuki'],
|
||||
['Bopo', 'Bopomofo'],
|
||||
['Brah', 'Brahmi'],
|
||||
['Brai', 'Braille'],
|
||||
['Bugi', 'Buginese'],
|
||||
['Buhd', 'Buhid'],
|
||||
['Cakm', 'Chakma'],
|
||||
['Cans', 'Canadian_Aboriginal'],
|
||||
['Cari', 'Carian'],
|
||||
['Cham', 'Cham'],
|
||||
['Cher', 'Cherokee'],
|
||||
['Copt', 'Coptic'],
|
||||
['Qaac', 'Coptic'],
|
||||
['Cprt', 'Cypriot'],
|
||||
['Cyrl', 'Cyrillic'],
|
||||
['Deva', 'Devanagari'],
|
||||
['Dogr', 'Dogra'],
|
||||
['Dsrt', 'Deseret'],
|
||||
['Dupl', 'Duployan'],
|
||||
['Egyp', 'Egyptian_Hieroglyphs'],
|
||||
['Elba', 'Elbasan'],
|
||||
['Ethi', 'Ethiopic'],
|
||||
['Geor', 'Georgian'],
|
||||
['Glag', 'Glagolitic'],
|
||||
['Gong', 'Gunjala_Gondi'],
|
||||
['Gonm', 'Masaram_Gondi'],
|
||||
['Goth', 'Gothic'],
|
||||
['Gran', 'Grantha'],
|
||||
['Grek', 'Greek'],
|
||||
['Gujr', 'Gujarati'],
|
||||
['Guru', 'Gurmukhi'],
|
||||
['Hang', 'Hangul'],
|
||||
['Hani', 'Han'],
|
||||
['Hano', 'Hanunoo'],
|
||||
['Hatr', 'Hatran'],
|
||||
['Hebr', 'Hebrew'],
|
||||
['Hira', 'Hiragana'],
|
||||
['Hluw', 'Anatolian_Hieroglyphs'],
|
||||
['Hmng', 'Pahawh_Hmong'],
|
||||
['Hrkt', 'Katakana_Or_Hiragana'],
|
||||
['Hung', 'Old_Hungarian'],
|
||||
['Ital', 'Old_Italic'],
|
||||
['Java', 'Javanese'],
|
||||
['Kali', 'Kayah_Li'],
|
||||
['Kana', 'Katakana'],
|
||||
['Khar', 'Kharoshthi'],
|
||||
['Khmr', 'Khmer'],
|
||||
['Khoj', 'Khojki'],
|
||||
['Knda', 'Kannada'],
|
||||
['Kthi', 'Kaithi'],
|
||||
['Lana', 'Tai_Tham'],
|
||||
['Laoo', 'Lao'],
|
||||
['Latn', 'Latin'],
|
||||
['Lepc', 'Lepcha'],
|
||||
['Limb', 'Limbu'],
|
||||
['Lina', 'Linear_A'],
|
||||
['Linb', 'Linear_B'],
|
||||
['Lisu', 'Lisu'],
|
||||
['Lyci', 'Lycian'],
|
||||
['Lydi', 'Lydian'],
|
||||
['Mahj', 'Mahajani'],
|
||||
['Maka', 'Makasar'],
|
||||
['Mand', 'Mandaic'],
|
||||
['Mani', 'Manichaean'],
|
||||
['Marc', 'Marchen'],
|
||||
['Medf', 'Medefaidrin'],
|
||||
['Mend', 'Mende_Kikakui'],
|
||||
['Merc', 'Meroitic_Cursive'],
|
||||
['Mero', 'Meroitic_Hieroglyphs'],
|
||||
['Mlym', 'Malayalam'],
|
||||
['Modi', 'Modi'],
|
||||
['Mong', 'Mongolian'],
|
||||
['Mroo', 'Mro'],
|
||||
['Mtei', 'Meetei_Mayek'],
|
||||
['Mult', 'Multani'],
|
||||
['Mymr', 'Myanmar'],
|
||||
['Narb', 'Old_North_Arabian'],
|
||||
['Nbat', 'Nabataean'],
|
||||
['Newa', 'Newa'],
|
||||
['Nkoo', 'Nko'],
|
||||
['Nshu', 'Nushu'],
|
||||
['Ogam', 'Ogham'],
|
||||
['Olck', 'Ol_Chiki'],
|
||||
['Orkh', 'Old_Turkic'],
|
||||
['Orya', 'Oriya'],
|
||||
['Osge', 'Osage'],
|
||||
['Osma', 'Osmanya'],
|
||||
['Palm', 'Palmyrene'],
|
||||
['Pauc', 'Pau_Cin_Hau'],
|
||||
['Perm', 'Old_Permic'],
|
||||
['Phag', 'Phags_Pa'],
|
||||
['Phli', 'Inscriptional_Pahlavi'],
|
||||
['Phlp', 'Psalter_Pahlavi'],
|
||||
['Phnx', 'Phoenician'],
|
||||
['Plrd', 'Miao'],
|
||||
['Prti', 'Inscriptional_Parthian'],
|
||||
['Rjng', 'Rejang'],
|
||||
['Rohg', 'Hanifi_Rohingya'],
|
||||
['Runr', 'Runic'],
|
||||
['Samr', 'Samaritan'],
|
||||
['Sarb', 'Old_South_Arabian'],
|
||||
['Saur', 'Saurashtra'],
|
||||
['Sgnw', 'SignWriting'],
|
||||
['Shaw', 'Shavian'],
|
||||
['Shrd', 'Sharada'],
|
||||
['Sidd', 'Siddham'],
|
||||
['Sind', 'Khudawadi'],
|
||||
['Sinh', 'Sinhala'],
|
||||
['Sogd', 'Sogdian'],
|
||||
['Sogo', 'Old_Sogdian'],
|
||||
['Sora', 'Sora_Sompeng'],
|
||||
['Soyo', 'Soyombo'],
|
||||
['Sund', 'Sundanese'],
|
||||
['Sylo', 'Syloti_Nagri'],
|
||||
['Syrc', 'Syriac'],
|
||||
['Tagb', 'Tagbanwa'],
|
||||
['Takr', 'Takri'],
|
||||
['Tale', 'Tai_Le'],
|
||||
['Talu', 'New_Tai_Lue'],
|
||||
['Taml', 'Tamil'],
|
||||
['Tang', 'Tangut'],
|
||||
['Tavt', 'Tai_Viet'],
|
||||
['Telu', 'Telugu'],
|
||||
['Tfng', 'Tifinagh'],
|
||||
['Tglg', 'Tagalog'],
|
||||
['Thaa', 'Thaana'],
|
||||
['Thai', 'Thai'],
|
||||
['Tibt', 'Tibetan'],
|
||||
['Tirh', 'Tirhuta'],
|
||||
['Ugar', 'Ugaritic'],
|
||||
['Vaii', 'Vai'],
|
||||
['Wara', 'Warang_Citi'],
|
||||
['Xpeo', 'Old_Persian'],
|
||||
['Xsux', 'Cuneiform'],
|
||||
['Yiii', 'Yi'],
|
||||
['Zanb', 'Zanabazar_Square'],
|
||||
['Zinh', 'Inherited'],
|
||||
['Qaai', 'Inherited'],
|
||||
['Zyyy', 'Common'],
|
||||
['Zzzz', 'Unknown'],
|
||||
['Adlam', 'Adlam'],
|
||||
['Caucasian_Albanian', 'Caucasian_Albanian'],
|
||||
['Arabic', 'Arabic'],
|
||||
['Imperial_Aramaic', 'Imperial_Aramaic'],
|
||||
['Armenian', 'Armenian'],
|
||||
['Avestan', 'Avestan'],
|
||||
['Balinese', 'Balinese'],
|
||||
['Bamum', 'Bamum'],
|
||||
['Bassa_Vah', 'Bassa_Vah'],
|
||||
['Batak', 'Batak'],
|
||||
['Bengali', 'Bengali'],
|
||||
['Bhaiksuki', 'Bhaiksuki'],
|
||||
['Bopomofo', 'Bopomofo'],
|
||||
['Brahmi', 'Brahmi'],
|
||||
['Braille', 'Braille'],
|
||||
['Buginese', 'Buginese'],
|
||||
['Buhid', 'Buhid'],
|
||||
['Chakma', 'Chakma'],
|
||||
['Canadian_Aboriginal', 'Canadian_Aboriginal'],
|
||||
['Carian', 'Carian'],
|
||||
['Cherokee', 'Cherokee'],
|
||||
['Coptic', 'Coptic'],
|
||||
['Cypriot', 'Cypriot'],
|
||||
['Cyrillic', 'Cyrillic'],
|
||||
['Devanagari', 'Devanagari'],
|
||||
['Dogra', 'Dogra'],
|
||||
['Deseret', 'Deseret'],
|
||||
['Duployan', 'Duployan'],
|
||||
['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
|
||||
['Elbasan', 'Elbasan'],
|
||||
['Ethiopic', 'Ethiopic'],
|
||||
['Georgian', 'Georgian'],
|
||||
['Glagolitic', 'Glagolitic'],
|
||||
['Gunjala_Gondi', 'Gunjala_Gondi'],
|
||||
['Masaram_Gondi', 'Masaram_Gondi'],
|
||||
['Gothic', 'Gothic'],
|
||||
['Grantha', 'Grantha'],
|
||||
['Greek', 'Greek'],
|
||||
['Gujarati', 'Gujarati'],
|
||||
['Gurmukhi', 'Gurmukhi'],
|
||||
['Hangul', 'Hangul'],
|
||||
['Han', 'Han'],
|
||||
['Hanunoo', 'Hanunoo'],
|
||||
['Hatran', 'Hatran'],
|
||||
['Hebrew', 'Hebrew'],
|
||||
['Hiragana', 'Hiragana'],
|
||||
['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
|
||||
['Pahawh_Hmong', 'Pahawh_Hmong'],
|
||||
['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
|
||||
['Old_Hungarian', 'Old_Hungarian'],
|
||||
['Old_Italic', 'Old_Italic'],
|
||||
['Javanese', 'Javanese'],
|
||||
['Kayah_Li', 'Kayah_Li'],
|
||||
['Katakana', 'Katakana'],
|
||||
['Kharoshthi', 'Kharoshthi'],
|
||||
['Khmer', 'Khmer'],
|
||||
['Khojki', 'Khojki'],
|
||||
['Kannada', 'Kannada'],
|
||||
['Kaithi', 'Kaithi'],
|
||||
['Tai_Tham', 'Tai_Tham'],
|
||||
['Lao', 'Lao'],
|
||||
['Latin', 'Latin'],
|
||||
['Lepcha', 'Lepcha'],
|
||||
['Limbu', 'Limbu'],
|
||||
['Linear_A', 'Linear_A'],
|
||||
['Linear_B', 'Linear_B'],
|
||||
['Lycian', 'Lycian'],
|
||||
['Lydian', 'Lydian'],
|
||||
['Mahajani', 'Mahajani'],
|
||||
['Makasar', 'Makasar'],
|
||||
['Mandaic', 'Mandaic'],
|
||||
['Manichaean', 'Manichaean'],
|
||||
['Marchen', 'Marchen'],
|
||||
['Medefaidrin', 'Medefaidrin'],
|
||||
['Mende_Kikakui', 'Mende_Kikakui'],
|
||||
['Meroitic_Cursive', 'Meroitic_Cursive'],
|
||||
['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
|
||||
['Malayalam', 'Malayalam'],
|
||||
['Mongolian', 'Mongolian'],
|
||||
['Mro', 'Mro'],
|
||||
['Meetei_Mayek', 'Meetei_Mayek'],
|
||||
['Multani', 'Multani'],
|
||||
['Myanmar', 'Myanmar'],
|
||||
['Old_North_Arabian', 'Old_North_Arabian'],
|
||||
['Nabataean', 'Nabataean'],
|
||||
['Nko', 'Nko'],
|
||||
['Nushu', 'Nushu'],
|
||||
['Ogham', 'Ogham'],
|
||||
['Ol_Chiki', 'Ol_Chiki'],
|
||||
['Old_Turkic', 'Old_Turkic'],
|
||||
['Oriya', 'Oriya'],
|
||||
['Osage', 'Osage'],
|
||||
['Osmanya', 'Osmanya'],
|
||||
['Palmyrene', 'Palmyrene'],
|
||||
['Pau_Cin_Hau', 'Pau_Cin_Hau'],
|
||||
['Old_Permic', 'Old_Permic'],
|
||||
['Phags_Pa', 'Phags_Pa'],
|
||||
['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
|
||||
['Psalter_Pahlavi', 'Psalter_Pahlavi'],
|
||||
['Phoenician', 'Phoenician'],
|
||||
['Miao', 'Miao'],
|
||||
['Inscriptional_Parthian', 'Inscriptional_Parthian'],
|
||||
['Rejang', 'Rejang'],
|
||||
['Hanifi_Rohingya', 'Hanifi_Rohingya'],
|
||||
['Runic', 'Runic'],
|
||||
['Samaritan', 'Samaritan'],
|
||||
['Old_South_Arabian', 'Old_South_Arabian'],
|
||||
['Saurashtra', 'Saurashtra'],
|
||||
['SignWriting', 'SignWriting'],
|
||||
['Shavian', 'Shavian'],
|
||||
['Sharada', 'Sharada'],
|
||||
['Siddham', 'Siddham'],
|
||||
['Khudawadi', 'Khudawadi'],
|
||||
['Sinhala', 'Sinhala'],
|
||||
['Sogdian', 'Sogdian'],
|
||||
['Old_Sogdian', 'Old_Sogdian'],
|
||||
['Sora_Sompeng', 'Sora_Sompeng'],
|
||||
['Soyombo', 'Soyombo'],
|
||||
['Sundanese', 'Sundanese'],
|
||||
['Syloti_Nagri', 'Syloti_Nagri'],
|
||||
['Syriac', 'Syriac'],
|
||||
['Tagbanwa', 'Tagbanwa'],
|
||||
['Takri', 'Takri'],
|
||||
['Tai_Le', 'Tai_Le'],
|
||||
['New_Tai_Lue', 'New_Tai_Lue'],
|
||||
['Tamil', 'Tamil'],
|
||||
['Tangut', 'Tangut'],
|
||||
['Tai_Viet', 'Tai_Viet'],
|
||||
['Telugu', 'Telugu'],
|
||||
['Tifinagh', 'Tifinagh'],
|
||||
['Tagalog', 'Tagalog'],
|
||||
['Thaana', 'Thaana'],
|
||||
['Tibetan', 'Tibetan'],
|
||||
['Tirhuta', 'Tirhuta'],
|
||||
['Ugaritic', 'Ugaritic'],
|
||||
['Vai', 'Vai'],
|
||||
['Warang_Citi', 'Warang_Citi'],
|
||||
['Old_Persian', 'Old_Persian'],
|
||||
['Cuneiform', 'Cuneiform'],
|
||||
['Yi', 'Yi'],
|
||||
['Zanabazar_Square', 'Zanabazar_Square'],
|
||||
['Inherited', 'Inherited'],
|
||||
['Common', 'Common'],
|
||||
['Unknown', 'Unknown']
|
||||
])],
|
||||
['Script_Extensions', new Map([
|
||||
['Adlm', 'Adlam'],
|
||||
['Aghb', 'Caucasian_Albanian'],
|
||||
['Ahom', 'Ahom'],
|
||||
['Arab', 'Arabic'],
|
||||
['Armi', 'Imperial_Aramaic'],
|
||||
['Armn', 'Armenian'],
|
||||
['Avst', 'Avestan'],
|
||||
['Bali', 'Balinese'],
|
||||
['Bamu', 'Bamum'],
|
||||
['Bass', 'Bassa_Vah'],
|
||||
['Batk', 'Batak'],
|
||||
['Beng', 'Bengali'],
|
||||
['Bhks', 'Bhaiksuki'],
|
||||
['Bopo', 'Bopomofo'],
|
||||
['Brah', 'Brahmi'],
|
||||
['Brai', 'Braille'],
|
||||
['Bugi', 'Buginese'],
|
||||
['Buhd', 'Buhid'],
|
||||
['Cakm', 'Chakma'],
|
||||
['Cans', 'Canadian_Aboriginal'],
|
||||
['Cari', 'Carian'],
|
||||
['Cham', 'Cham'],
|
||||
['Cher', 'Cherokee'],
|
||||
['Copt', 'Coptic'],
|
||||
['Qaac', 'Coptic'],
|
||||
['Cprt', 'Cypriot'],
|
||||
['Cyrl', 'Cyrillic'],
|
||||
['Deva', 'Devanagari'],
|
||||
['Dogr', 'Dogra'],
|
||||
['Dsrt', 'Deseret'],
|
||||
['Dupl', 'Duployan'],
|
||||
['Egyp', 'Egyptian_Hieroglyphs'],
|
||||
['Elba', 'Elbasan'],
|
||||
['Ethi', 'Ethiopic'],
|
||||
['Geor', 'Georgian'],
|
||||
['Glag', 'Glagolitic'],
|
||||
['Gong', 'Gunjala_Gondi'],
|
||||
['Gonm', 'Masaram_Gondi'],
|
||||
['Goth', 'Gothic'],
|
||||
['Gran', 'Grantha'],
|
||||
['Grek', 'Greek'],
|
||||
['Gujr', 'Gujarati'],
|
||||
['Guru', 'Gurmukhi'],
|
||||
['Hang', 'Hangul'],
|
||||
['Hani', 'Han'],
|
||||
['Hano', 'Hanunoo'],
|
||||
['Hatr', 'Hatran'],
|
||||
['Hebr', 'Hebrew'],
|
||||
['Hira', 'Hiragana'],
|
||||
['Hluw', 'Anatolian_Hieroglyphs'],
|
||||
['Hmng', 'Pahawh_Hmong'],
|
||||
['Hrkt', 'Katakana_Or_Hiragana'],
|
||||
['Hung', 'Old_Hungarian'],
|
||||
['Ital', 'Old_Italic'],
|
||||
['Java', 'Javanese'],
|
||||
['Kali', 'Kayah_Li'],
|
||||
['Kana', 'Katakana'],
|
||||
['Khar', 'Kharoshthi'],
|
||||
['Khmr', 'Khmer'],
|
||||
['Khoj', 'Khojki'],
|
||||
['Knda', 'Kannada'],
|
||||
['Kthi', 'Kaithi'],
|
||||
['Lana', 'Tai_Tham'],
|
||||
['Laoo', 'Lao'],
|
||||
['Latn', 'Latin'],
|
||||
['Lepc', 'Lepcha'],
|
||||
['Limb', 'Limbu'],
|
||||
['Lina', 'Linear_A'],
|
||||
['Linb', 'Linear_B'],
|
||||
['Lisu', 'Lisu'],
|
||||
['Lyci', 'Lycian'],
|
||||
['Lydi', 'Lydian'],
|
||||
['Mahj', 'Mahajani'],
|
||||
['Maka', 'Makasar'],
|
||||
['Mand', 'Mandaic'],
|
||||
['Mani', 'Manichaean'],
|
||||
['Marc', 'Marchen'],
|
||||
['Medf', 'Medefaidrin'],
|
||||
['Mend', 'Mende_Kikakui'],
|
||||
['Merc', 'Meroitic_Cursive'],
|
||||
['Mero', 'Meroitic_Hieroglyphs'],
|
||||
['Mlym', 'Malayalam'],
|
||||
['Modi', 'Modi'],
|
||||
['Mong', 'Mongolian'],
|
||||
['Mroo', 'Mro'],
|
||||
['Mtei', 'Meetei_Mayek'],
|
||||
['Mult', 'Multani'],
|
||||
['Mymr', 'Myanmar'],
|
||||
['Narb', 'Old_North_Arabian'],
|
||||
['Nbat', 'Nabataean'],
|
||||
['Newa', 'Newa'],
|
||||
['Nkoo', 'Nko'],
|
||||
['Nshu', 'Nushu'],
|
||||
['Ogam', 'Ogham'],
|
||||
['Olck', 'Ol_Chiki'],
|
||||
['Orkh', 'Old_Turkic'],
|
||||
['Orya', 'Oriya'],
|
||||
['Osge', 'Osage'],
|
||||
['Osma', 'Osmanya'],
|
||||
['Palm', 'Palmyrene'],
|
||||
['Pauc', 'Pau_Cin_Hau'],
|
||||
['Perm', 'Old_Permic'],
|
||||
['Phag', 'Phags_Pa'],
|
||||
['Phli', 'Inscriptional_Pahlavi'],
|
||||
['Phlp', 'Psalter_Pahlavi'],
|
||||
['Phnx', 'Phoenician'],
|
||||
['Plrd', 'Miao'],
|
||||
['Prti', 'Inscriptional_Parthian'],
|
||||
['Rjng', 'Rejang'],
|
||||
['Rohg', 'Hanifi_Rohingya'],
|
||||
['Runr', 'Runic'],
|
||||
['Samr', 'Samaritan'],
|
||||
['Sarb', 'Old_South_Arabian'],
|
||||
['Saur', 'Saurashtra'],
|
||||
['Sgnw', 'SignWriting'],
|
||||
['Shaw', 'Shavian'],
|
||||
['Shrd', 'Sharada'],
|
||||
['Sidd', 'Siddham'],
|
||||
['Sind', 'Khudawadi'],
|
||||
['Sinh', 'Sinhala'],
|
||||
['Sogd', 'Sogdian'],
|
||||
['Sogo', 'Old_Sogdian'],
|
||||
['Sora', 'Sora_Sompeng'],
|
||||
['Soyo', 'Soyombo'],
|
||||
['Sund', 'Sundanese'],
|
||||
['Sylo', 'Syloti_Nagri'],
|
||||
['Syrc', 'Syriac'],
|
||||
['Tagb', 'Tagbanwa'],
|
||||
['Takr', 'Takri'],
|
||||
['Tale', 'Tai_Le'],
|
||||
['Talu', 'New_Tai_Lue'],
|
||||
['Taml', 'Tamil'],
|
||||
['Tang', 'Tangut'],
|
||||
['Tavt', 'Tai_Viet'],
|
||||
['Telu', 'Telugu'],
|
||||
['Tfng', 'Tifinagh'],
|
||||
['Tglg', 'Tagalog'],
|
||||
['Thaa', 'Thaana'],
|
||||
['Thai', 'Thai'],
|
||||
['Tibt', 'Tibetan'],
|
||||
['Tirh', 'Tirhuta'],
|
||||
['Ugar', 'Ugaritic'],
|
||||
['Vaii', 'Vai'],
|
||||
['Wara', 'Warang_Citi'],
|
||||
['Xpeo', 'Old_Persian'],
|
||||
['Xsux', 'Cuneiform'],
|
||||
['Yiii', 'Yi'],
|
||||
['Zanb', 'Zanabazar_Square'],
|
||||
['Zinh', 'Inherited'],
|
||||
['Qaai', 'Inherited'],
|
||||
['Zyyy', 'Common'],
|
||||
['Zzzz', 'Unknown'],
|
||||
['Adlam', 'Adlam'],
|
||||
['Caucasian_Albanian', 'Caucasian_Albanian'],
|
||||
['Arabic', 'Arabic'],
|
||||
['Imperial_Aramaic', 'Imperial_Aramaic'],
|
||||
['Armenian', 'Armenian'],
|
||||
['Avestan', 'Avestan'],
|
||||
['Balinese', 'Balinese'],
|
||||
['Bamum', 'Bamum'],
|
||||
['Bassa_Vah', 'Bassa_Vah'],
|
||||
['Batak', 'Batak'],
|
||||
['Bengali', 'Bengali'],
|
||||
['Bhaiksuki', 'Bhaiksuki'],
|
||||
['Bopomofo', 'Bopomofo'],
|
||||
['Brahmi', 'Brahmi'],
|
||||
['Braille', 'Braille'],
|
||||
['Buginese', 'Buginese'],
|
||||
['Buhid', 'Buhid'],
|
||||
['Chakma', 'Chakma'],
|
||||
['Canadian_Aboriginal', 'Canadian_Aboriginal'],
|
||||
['Carian', 'Carian'],
|
||||
['Cherokee', 'Cherokee'],
|
||||
['Coptic', 'Coptic'],
|
||||
['Cypriot', 'Cypriot'],
|
||||
['Cyrillic', 'Cyrillic'],
|
||||
['Devanagari', 'Devanagari'],
|
||||
['Dogra', 'Dogra'],
|
||||
['Deseret', 'Deseret'],
|
||||
['Duployan', 'Duployan'],
|
||||
['Egyptian_Hieroglyphs', 'Egyptian_Hieroglyphs'],
|
||||
['Elbasan', 'Elbasan'],
|
||||
['Ethiopic', 'Ethiopic'],
|
||||
['Georgian', 'Georgian'],
|
||||
['Glagolitic', 'Glagolitic'],
|
||||
['Gunjala_Gondi', 'Gunjala_Gondi'],
|
||||
['Masaram_Gondi', 'Masaram_Gondi'],
|
||||
['Gothic', 'Gothic'],
|
||||
['Grantha', 'Grantha'],
|
||||
['Greek', 'Greek'],
|
||||
['Gujarati', 'Gujarati'],
|
||||
['Gurmukhi', 'Gurmukhi'],
|
||||
['Hangul', 'Hangul'],
|
||||
['Han', 'Han'],
|
||||
['Hanunoo', 'Hanunoo'],
|
||||
['Hatran', 'Hatran'],
|
||||
['Hebrew', 'Hebrew'],
|
||||
['Hiragana', 'Hiragana'],
|
||||
['Anatolian_Hieroglyphs', 'Anatolian_Hieroglyphs'],
|
||||
['Pahawh_Hmong', 'Pahawh_Hmong'],
|
||||
['Katakana_Or_Hiragana', 'Katakana_Or_Hiragana'],
|
||||
['Old_Hungarian', 'Old_Hungarian'],
|
||||
['Old_Italic', 'Old_Italic'],
|
||||
['Javanese', 'Javanese'],
|
||||
['Kayah_Li', 'Kayah_Li'],
|
||||
['Katakana', 'Katakana'],
|
||||
['Kharoshthi', 'Kharoshthi'],
|
||||
['Khmer', 'Khmer'],
|
||||
['Khojki', 'Khojki'],
|
||||
['Kannada', 'Kannada'],
|
||||
['Kaithi', 'Kaithi'],
|
||||
['Tai_Tham', 'Tai_Tham'],
|
||||
['Lao', 'Lao'],
|
||||
['Latin', 'Latin'],
|
||||
['Lepcha', 'Lepcha'],
|
||||
['Limbu', 'Limbu'],
|
||||
['Linear_A', 'Linear_A'],
|
||||
['Linear_B', 'Linear_B'],
|
||||
['Lycian', 'Lycian'],
|
||||
['Lydian', 'Lydian'],
|
||||
['Mahajani', 'Mahajani'],
|
||||
['Makasar', 'Makasar'],
|
||||
['Mandaic', 'Mandaic'],
|
||||
['Manichaean', 'Manichaean'],
|
||||
['Marchen', 'Marchen'],
|
||||
['Medefaidrin', 'Medefaidrin'],
|
||||
['Mende_Kikakui', 'Mende_Kikakui'],
|
||||
['Meroitic_Cursive', 'Meroitic_Cursive'],
|
||||
['Meroitic_Hieroglyphs', 'Meroitic_Hieroglyphs'],
|
||||
['Malayalam', 'Malayalam'],
|
||||
['Mongolian', 'Mongolian'],
|
||||
['Mro', 'Mro'],
|
||||
['Meetei_Mayek', 'Meetei_Mayek'],
|
||||
['Multani', 'Multani'],
|
||||
['Myanmar', 'Myanmar'],
|
||||
['Old_North_Arabian', 'Old_North_Arabian'],
|
||||
['Nabataean', 'Nabataean'],
|
||||
['Nko', 'Nko'],
|
||||
['Nushu', 'Nushu'],
|
||||
['Ogham', 'Ogham'],
|
||||
['Ol_Chiki', 'Ol_Chiki'],
|
||||
['Old_Turkic', 'Old_Turkic'],
|
||||
['Oriya', 'Oriya'],
|
||||
['Osage', 'Osage'],
|
||||
['Osmanya', 'Osmanya'],
|
||||
['Palmyrene', 'Palmyrene'],
|
||||
['Pau_Cin_Hau', 'Pau_Cin_Hau'],
|
||||
['Old_Permic', 'Old_Permic'],
|
||||
['Phags_Pa', 'Phags_Pa'],
|
||||
['Inscriptional_Pahlavi', 'Inscriptional_Pahlavi'],
|
||||
['Psalter_Pahlavi', 'Psalter_Pahlavi'],
|
||||
['Phoenician', 'Phoenician'],
|
||||
['Miao', 'Miao'],
|
||||
['Inscriptional_Parthian', 'Inscriptional_Parthian'],
|
||||
['Rejang', 'Rejang'],
|
||||
['Hanifi_Rohingya', 'Hanifi_Rohingya'],
|
||||
['Runic', 'Runic'],
|
||||
['Samaritan', 'Samaritan'],
|
||||
['Old_South_Arabian', 'Old_South_Arabian'],
|
||||
['Saurashtra', 'Saurashtra'],
|
||||
['SignWriting', 'SignWriting'],
|
||||
['Shavian', 'Shavian'],
|
||||
['Sharada', 'Sharada'],
|
||||
['Siddham', 'Siddham'],
|
||||
['Khudawadi', 'Khudawadi'],
|
||||
['Sinhala', 'Sinhala'],
|
||||
['Sogdian', 'Sogdian'],
|
||||
['Old_Sogdian', 'Old_Sogdian'],
|
||||
['Sora_Sompeng', 'Sora_Sompeng'],
|
||||
['Soyombo', 'Soyombo'],
|
||||
['Sundanese', 'Sundanese'],
|
||||
['Syloti_Nagri', 'Syloti_Nagri'],
|
||||
['Syriac', 'Syriac'],
|
||||
['Tagbanwa', 'Tagbanwa'],
|
||||
['Takri', 'Takri'],
|
||||
['Tai_Le', 'Tai_Le'],
|
||||
['New_Tai_Lue', 'New_Tai_Lue'],
|
||||
['Tamil', 'Tamil'],
|
||||
['Tangut', 'Tangut'],
|
||||
['Tai_Viet', 'Tai_Viet'],
|
||||
['Telugu', 'Telugu'],
|
||||
['Tifinagh', 'Tifinagh'],
|
||||
['Tagalog', 'Tagalog'],
|
||||
['Thaana', 'Thaana'],
|
||||
['Tibetan', 'Tibetan'],
|
||||
['Tirhuta', 'Tirhuta'],
|
||||
['Ugaritic', 'Ugaritic'],
|
||||
['Vai', 'Vai'],
|
||||
['Warang_Citi', 'Warang_Citi'],
|
||||
['Old_Persian', 'Old_Persian'],
|
||||
['Cuneiform', 'Cuneiform'],
|
||||
['Yi', 'Yi'],
|
||||
['Zanabazar_Square', 'Zanabazar_Square'],
|
||||
['Inherited', 'Inherited'],
|
||||
['Common', 'Common'],
|
||||
['Unknown', 'Unknown']
|
||||
])]
|
||||
]);
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const propertyToValueAliases = require('./data/mappings.js');
|
||||
|
||||
const matchPropertyValue = function(property, value) {
|
||||
const aliasToValue = propertyToValueAliases.get(property);
|
||||
if (!aliasToValue) {
|
||||
throw new Error(`Unknown property \`${ property }\`.`);
|
||||
}
|
||||
const canonicalValue = aliasToValue.get(value);
|
||||
if (canonicalValue) {
|
||||
return canonicalValue;
|
||||
}
|
||||
throw new Error(
|
||||
`Unknown value \`${ value }\` for property \`${ property }\`.`
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = matchPropertyValue;
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "unicode-match-property-value-ecmascript",
|
||||
"version": "1.0.2",
|
||||
"description": "Match a Unicode property or property alias to its canonical property name per the algorithm used for RegExp Unicode property escapes in ECMAScript.",
|
||||
"homepage": "https://github.com/mathiasbynens/unicode-match-property-value-ecmascript",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE-MIT.txt",
|
||||
"data/mappings.js",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"unicode",
|
||||
"unicode property values",
|
||||
"unicode property value aliases"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathiasbynens/unicode-match-property-value-ecmascript.git"
|
||||
},
|
||||
"bugs": "https://github.com/mathiasbynens/unicode-match-property-value-ecmascript/issues",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"jsesc": "^2.5.1",
|
||||
"unicode-property-value-aliases-ecmascript": "^1.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node scripts/build.js",
|
||||
"test": "ava ./tests"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,38 @@
|
|||
# unicode-property-aliases-ecmascript [![Build status](https://travis-ci.org/mathiasbynens/unicode-property-aliases-ecmascript.svg?branch=master)](https://travis-ci.org/mathiasbynens/unicode-property-aliases-ecmascript)
|
||||
|
||||
_unicode-property-aliases-ecmascript_ offers Unicode property alias mappings in an easy-to-consume JavaScript format. It only contains the Unicode property names that are supported in [ECMAScript RegExp property escapes](https://github.com/tc39/proposal-regexp-unicode-property-escapes).
|
||||
|
||||
It’s based on [the `PropertyAliases.txt` data for Unicode v11.0.0](http://unicode.org/Public/11.0.0/ucd/PropertyAliases.txt).
|
||||
|
||||
## Installation
|
||||
|
||||
To use _unicode-property-aliases-ecmascript_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
|
||||
|
||||
```bash
|
||||
$ npm install unicode-property-aliases-ecmascript
|
||||
```
|
||||
|
||||
Then, `require` it:
|
||||
|
||||
```js
|
||||
const propertyAliases = require('unicode-property-aliases-ecmascript');
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This module exports a `Map` object. The most common usage is to convert a property alias to its canonical form:
|
||||
|
||||
```js
|
||||
propertyAliases.get('scx')
|
||||
// → 'Script_Extensions'
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|
||||
|---|
|
||||
| [Mathias Bynens](https://mathiasbynens.be/) |
|
||||
|
||||
## License
|
||||
|
||||
_unicode-property-aliases-ecmascript_ is available under the [MIT](https://mths.be/mit) license.
|
|
@ -0,0 +1,51 @@
|
|||
// Generated using `npm run build`. Do not edit!
|
||||
module.exports = new Map([
|
||||
['scx', 'Script_Extensions'],
|
||||
['sc', 'Script'],
|
||||
['gc', 'General_Category'],
|
||||
['AHex', 'ASCII_Hex_Digit'],
|
||||
['Alpha', 'Alphabetic'],
|
||||
['Bidi_C', 'Bidi_Control'],
|
||||
['Bidi_M', 'Bidi_Mirrored'],
|
||||
['Cased', 'Cased'],
|
||||
['CI', 'Case_Ignorable'],
|
||||
['CWCF', 'Changes_When_Casefolded'],
|
||||
['CWCM', 'Changes_When_Casemapped'],
|
||||
['CWKCF', 'Changes_When_NFKC_Casefolded'],
|
||||
['CWL', 'Changes_When_Lowercased'],
|
||||
['CWT', 'Changes_When_Titlecased'],
|
||||
['CWU', 'Changes_When_Uppercased'],
|
||||
['Dash', 'Dash'],
|
||||
['Dep', 'Deprecated'],
|
||||
['DI', 'Default_Ignorable_Code_Point'],
|
||||
['Dia', 'Diacritic'],
|
||||
['Ext', 'Extender'],
|
||||
['Gr_Base', 'Grapheme_Base'],
|
||||
['Gr_Ext', 'Grapheme_Extend'],
|
||||
['Hex', 'Hex_Digit'],
|
||||
['IDC', 'ID_Continue'],
|
||||
['Ideo', 'Ideographic'],
|
||||
['IDS', 'ID_Start'],
|
||||
['IDSB', 'IDS_Binary_Operator'],
|
||||
['IDST', 'IDS_Trinary_Operator'],
|
||||
['Join_C', 'Join_Control'],
|
||||
['LOE', 'Logical_Order_Exception'],
|
||||
['Lower', 'Lowercase'],
|
||||
['Math', 'Math'],
|
||||
['NChar', 'Noncharacter_Code_Point'],
|
||||
['Pat_Syn', 'Pattern_Syntax'],
|
||||
['Pat_WS', 'Pattern_White_Space'],
|
||||
['QMark', 'Quotation_Mark'],
|
||||
['Radical', 'Radical'],
|
||||
['RI', 'Regional_Indicator'],
|
||||
['SD', 'Soft_Dotted'],
|
||||
['STerm', 'Sentence_Terminal'],
|
||||
['Term', 'Terminal_Punctuation'],
|
||||
['UIdeo', 'Unified_Ideograph'],
|
||||
['Upper', 'Uppercase'],
|
||||
['VS', 'Variation_Selector'],
|
||||
['WSpace', 'White_Space'],
|
||||
['space', 'White_Space'],
|
||||
['XIDC', 'XID_Continue'],
|
||||
['XIDS', 'XID_Start']
|
||||
]);
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "unicode-property-aliases-ecmascript",
|
||||
"version": "1.0.4",
|
||||
"description": "Unicode property alias mappings in JavaScript format for property names that are supported in ECMAScript RegExp property escapes.",
|
||||
"homepage": "https://github.com/mathiasbynens/unicode-property-aliases-ecmascript",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE-MIT.txt",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"unicode",
|
||||
"unicode-data",
|
||||
"alias",
|
||||
"aliases",
|
||||
"property alias"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathiasbynens/unicode-property-aliases-ecmascript.git"
|
||||
},
|
||||
"bugs": "https://github.com/mathiasbynens/unicode-property-aliases-ecmascript/issues",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"jsesc": "^2.5.1",
|
||||
"unicode-canonical-property-names-ecmascript": "^1.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"download": "curl http://unicode.org/Public/11.0.0/ucd/PropertyAliases.txt > data/PropertyAliases.txt",
|
||||
"build": "node scripts/build.js",
|
||||
"test": "ava ./tests"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"name": "lambdaworld",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "lambdaworld",
|
||||
"version": "0.0.1",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"shift-ast": "^7.0.0",
|
||||
"shift-parser": "^8.0.0",
|
||||
"shift-reducer": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/multimap": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz",
|
||||
"integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw=="
|
||||
},
|
||||
"node_modules/shift-ast": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-7.0.0.tgz",
|
||||
"integrity": "sha512-O0INwsZa1XH/lMSf52udGnjNOxKBLxFiZHt0Ys3i6bqtwuGEA3eDR4+e0qJELIsCy8+BiTtlTgQzP76K1ehipQ=="
|
||||
},
|
||||
"node_modules/shift-parser": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-parser/-/shift-parser-8.0.0.tgz",
|
||||
"integrity": "sha512-IShW1wGhvA5e+SPNVQ+Dwi/Be6651F2jZc6wwYHbYW7PiswAYfvR/v3Q+CjjxsVCna5L6J5OtR6y+tkkCzvCfw==",
|
||||
"dependencies": {
|
||||
"multimap": "^1.0.2",
|
||||
"shift-ast": "7.0.0",
|
||||
"shift-reducer": "7.0.0",
|
||||
"shift-regexp-acceptor": "3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shift-reducer": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-7.0.0.tgz",
|
||||
"integrity": "sha512-9igIDMHzp1+CkQZITGHM1sAd9jqMPV0vhqHuh8jlYumHSMIwsYcrDeo1tlpzNRUnfbEq1nLyh8Bf1YU8HGUE7g==",
|
||||
"dependencies": {
|
||||
"shift-ast": "7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shift-regexp-acceptor": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shift-regexp-acceptor/-/shift-regexp-acceptor-3.0.0.tgz",
|
||||
"integrity": "sha512-98UKizBjHY6SjjLUr51YYw4rtR+vxjGFm8znqNsoahesAI8Y9+WVAyiBCxxkov1KSDhW0Wz8FwwUqHnlFnjdUg==",
|
||||
"dependencies": {
|
||||
"unicode-match-property-ecmascript": "1.0.4",
|
||||
"unicode-match-property-value-ecmascript": "1.0.2",
|
||||
"unicode-property-aliases-ecmascript": "1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-canonical-property-names-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-match-property-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==",
|
||||
"dependencies": {
|
||||
"unicode-canonical-property-names-ecmascript": "^1.0.4",
|
||||
"unicode-property-aliases-ecmascript": "^1.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-match-property-value-ecmascript": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz",
|
||||
"integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/unicode-property-aliases-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz",
|
||||
"integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "lambdaworld",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"shift-ast": "^7.0.0",
|
||||
"shift-parser": "^8.0.0",
|
||||
"shift-reducer": "^7.0.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue