CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/zaach/reflect.js/master/lib/nodes.js
accept-ranges: bytes
age: 0
date: Fri, 18 Jul 2025 20:38:50 GMT
via: 1.1 varnish
x-served-by: cache-bom4748-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1752871130.639861,VS0,VE1146
vary: Accept-Encoding
x-fastly-request-id: 2655fc545baac0cadcbf4495b67264d8362d4fb1
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"1bdeedc06280e5552ee499679a7cf37915132720e58b9a9ef8082325120195fa"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: 35DE:47CCE:24087:6E09B:687AB0DA
content-encoding: gzip
accept-ranges: bytes
date: Fri, 18 Jul 2025 20:38:51 GMT
via: 1.1 varnish
x-served-by: cache-bom4749-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1752871131.840690,VS0,VE347
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 28e0f62156aa02d98eb36e079cf97d6cdf811e38
expires: Fri, 18 Jul 2025 20:43:51 GMT
source-age: 0
content-length: 1512
exports.defineNodes = function (builder) {
var defaultIni = function (loc) {
this.loc = loc;
return this;
};
var def = function def(name, ini) {
builder[name[0].toLowerCase()+name.slice(1)] = function (a,b,c,d,e,f,g,h) {
var obj = {};
obj.type = name;
ini.call(obj,a,b,c,d,e,f,g,h);
if (obj.loc) {
obj.range = obj.loc.range || [0,0];
delete obj.loc;
obj.loc = arguments[ini.length-(name=='Literal' ? 2:1)];
delete obj.loc.range;
}
return obj;
};
};
/* Nodes
*/
// used in cases where object and array literals are valid expressions
function convertExprToPattern (expr) {
if (expr.type == 'ObjectExpression') {
expr.type = 'ObjectPattern';
} else if (expr.type == 'ArrayExpression') {
expr.type = 'ArrayPattern';
}
}
// Program node
def('Program', function (elements,loc) {
this.body = elements;
this.loc = loc;
});
def('ExpressionStatement', function (expression, loc) {
this.expression = expression;
this.loc = loc;
});
def('BlockStatement', function (body, loc) {
this.body = body;
this.loc = loc;
});
def('EmptyStatement', defaultIni);
// Identifier node
def('Identifier', function (name,loc) {
this.name = name;
this.loc = loc;
});
// Literal expression node
def('Literal', function (val, loc, raw) {
this.value = val;
if (raw) this.raw = raw;
this.loc = loc;
});
// "this" expression node
def('ThisExpression', defaultIni);
// Var statement node
def('VariableDeclaration', function (kind, declarations, loc) {
this.declarations = declarations;
this.kind = kind;
this.loc = loc;
});
def('VariableDeclarator', function (id, init, loc) {
this.id = id;
this.init = init;
this.loc = loc;
});
def('ArrayExpression', function (elements, loc) {
this.elements = elements;
this.loc = loc;
});
def('ObjectExpression', function (properties, loc) {
this.properties = properties;
this.loc = loc;
});
def('Property', function (key, value, kind, loc) {
this.key = key;
this.value = value;
this.kind = kind;
this.loc = loc;
});
// Function declaration node
var funIni = function (ident, params, body, isGen, isExp, loc) {
this.id = ident;
this.params = params;
this.body = body;
this.loc = loc;
if (!this.expression) {
this.body.body.forEach(function (el) {
if (el.type == "VariableDeclaration" && el.kind == "let") {
el.kind = "var";
}
});
}
};
def('FunctionDeclaration', funIni);
def('FunctionExpression', funIni);
// return statement node
def('ReturnStatement', function (argument, loc) {
this.argument = argument;
this.loc = loc;
});
def('TryStatement', function (block, handlers, finalizer, loc) {
this.block = block;
this.handlers = handlers || [];
this.finalizer = finalizer;
this.loc = loc;
});
def('CatchClause', function (param, guard, body, loc) {
this.param = param;
this.guard = guard;
this.body = body;
this.loc = loc;
});
def('ThrowStatement', function (argument, loc) {
this.argument = argument;
this.loc = loc;
});
def('LabeledStatement', function (label, body, loc) {
this.label = label;
this.body = body;
this.loc = loc;
});
def('BreakStatement', function (label, loc) {
this.label = label;
this.loc = loc;
});
def('ContinueStatement', function (label, loc) {
this.label = label;
this.loc = loc;
});
def('SwitchStatement', function (discriminant, cases, lexical, loc) {
this.discriminant = discriminant;
if (cases.length) this.cases = cases;
this.loc = loc;
});
def('SwitchCase', function (test, consequent, loc) {
this.test = test;
this.consequent = consequent;
this.loc = loc;
});
def('WithStatement', function (object, body, loc) {
this.object = object;
this.body = body;
this.loc = loc;
});
// operators
def('ConditionalExpression', function (test, consequent, alternate, loc) {
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
this.loc = loc;
});
def('SequenceExpression', function (expressions, loc) {
this.expressions = expressions;
this.loc = loc;
});
def('BinaryExpression', function (op, left, right, loc) {
this.operator = op;
this.left = left;
this.right = right;
this.loc = loc;
});
def('AssignmentExpression', function (op, left, right, loc) {
this.operator = op;
this.left = left;
this.right = right;
this.loc = loc;
convertExprToPattern(left);
});
def('LogicalExpression', function (op, left, right, loc) {
this.operator = op;
this.left = left;
this.right = right;
this.loc = loc;
});
def('UnaryExpression', function (operator, argument, prefix, loc) {
this.operator = operator;
this.argument = argument;
this.prefix = prefix;
this.loc = loc;
});
def('UpdateExpression', function (operator, argument, prefix, loc) {
this.operator = operator;
this.argument = argument;
this.prefix = prefix;
this.loc = loc;
});
def('CallExpression', function (callee, args, loc) {
this.callee = callee;
this["arguments"] = args;
this.loc = loc;
});
def('NewExpression', function (callee, args, loc) {
this.callee = callee;
this["arguments"] = args;
this.loc = loc;
});
def('MemberExpression', function (object, property, computed, loc) {
this.object = object;
this.property = property;
this.computed = computed;
this.loc = loc;
});
// debugger node
def('DebuggerStatement', defaultIni);
// empty node
def('Empty', defaultIni);
// control structs
def('WhileStatement', function (test, body, loc) {
this.test = test;
this.body = body;
this.loc = loc;
});
def('DoWhileStatement', function (body, test, loc) {
this.body = body;
this.test = test;
this.loc = loc;
});
def('ForStatement', function (init, test, update, body, loc) {
this.init = init;
this.test = test;
this.update = update;
this.body = body;
this.loc = loc;
if (init) convertExprToPattern(init);
});
def('ForInStatement', function (left, right, body, each, loc) {
this.left = left;
this.right = right;
this.body = body;
this.each = !!each;
this.loc = loc;
convertExprToPattern(left);
});
def('IfStatement', function (test, consequent, alternate, loc) {
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
this.loc = loc;
});
def('ObjectPattern', function (properties, loc) {
this.properties = properties;
this.loc = loc;
});
def('ArrayPattern', function (elements, loc) {
this.elements = elements;
this.loc = loc;
});
return def;
};