/usr/lib/nodejs/acorn/tokencontext.js is in node-acorn 5.4.1+ds1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | "use strict";
var $$state$$ = require("./state"), $$tokentype$$ = require("./tokentype"), $$whitespace$$ = require("./whitespace");
class TokContext {
constructor(token, isExpr, preserveSpace, override, generator) {
this.token = token
this.isExpr = !!isExpr
this.preserveSpace = !!preserveSpace
this.override = override
this.generator = !!generator
}
}
const types = {
b_stat: new TokContext("{", false),
b_expr: new TokContext("{", true),
b_tmpl: new TokContext("${", false),
p_stat: new TokContext("(", false),
p_expr: new TokContext("(", true),
q_tmpl: new TokContext("`", true, true, p => p.tryReadTemplateToken()),
f_stat: new TokContext("function", false),
f_expr: new TokContext("function", true),
f_expr_gen: new TokContext("function", true, false, null, true),
f_gen: new TokContext("function", false, false, null, true)
};
const pp = $$state$$.Parser.prototype
pp.initialContext = function() {
return [types.b_stat]
}
pp.braceIsBlock = function(prevType) {
let parent = this.curContext()
if (parent === types.f_expr || parent === types.f_stat)
return true
if (prevType === $$tokentype$$.types.colon && (parent === types.b_stat || parent === types.b_expr))
return !parent.isExpr
// The check for `tt.name && exprAllowed` detects whether we are
// after a `yield` or `of` construct. See the `updateContext` for
// `tt.name`.
if (prevType === $$tokentype$$.types._return || prevType == $$tokentype$$.types.name && this.exprAllowed)
return $$whitespace$$.lineBreak.test(this.input.slice(this.lastTokEnd, this.start));
if (prevType === $$tokentype$$.types._else || prevType === $$tokentype$$.types.semi || prevType === $$tokentype$$.types.eof || prevType === $$tokentype$$.types.parenR || prevType == $$tokentype$$.types.arrow)
return true
if (prevType == $$tokentype$$.types.braceL)
return parent === types.b_stat
if (prevType == $$tokentype$$.types._var || prevType == $$tokentype$$.types.name)
return false
return !this.exprAllowed
}
pp.inGeneratorContext = function() {
for (let i = this.context.length - 1; i >= 1; i--) {
let context = this.context[i]
if (context.token === "function")
return context.generator
}
return false
}
pp.updateContext = function(prevType) {
let update, type = this.type
if (type.keyword && prevType == $$tokentype$$.types.dot)
this.exprAllowed = false
else if (update = type.updateContext)
update.call(this, prevType)
else
this.exprAllowed = type.beforeExpr
}
// Token-specific context update code
$$tokentype$$.types.parenR.updateContext = $$tokentype$$.types.braceR.updateContext = function() {
if (this.context.length == 1) {
this.exprAllowed = true
return
}
let out = this.context.pop()
if (out === types.b_stat && this.curContext().token === "function") {
out = this.context.pop()
}
this.exprAllowed = !out.isExpr
}
$$tokentype$$.types.braceL.updateContext = function(prevType) {
this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr)
this.exprAllowed = true
}
$$tokentype$$.types.dollarBraceL.updateContext = function() {
this.context.push(types.b_tmpl)
this.exprAllowed = true
}
$$tokentype$$.types.parenL.updateContext = function(prevType) {
let statementParens = prevType === $$tokentype$$.types._if || prevType === $$tokentype$$.types._for || prevType === $$tokentype$$.types._with || prevType === $$tokentype$$.types._while
this.context.push(statementParens ? types.p_stat : types.p_expr)
this.exprAllowed = true
}
$$tokentype$$.types.incDec.updateContext = function() {
// tokExprAllowed stays unchanged
}
$$tokentype$$.types._function.updateContext = $$tokentype$$.types._class.updateContext = function(prevType) {
if (prevType.beforeExpr && prevType !== $$tokentype$$.types.semi && prevType !== $$tokentype$$.types._else &&
!((prevType === $$tokentype$$.types.colon || prevType === $$tokentype$$.types.braceL) && this.curContext() === types.b_stat))
this.context.push(types.f_expr)
else
this.context.push(types.f_stat)
this.exprAllowed = false
}
$$tokentype$$.types.backQuote.updateContext = function() {
if (this.curContext() === types.q_tmpl)
this.context.pop()
else
this.context.push(types.q_tmpl)
this.exprAllowed = false
}
$$tokentype$$.types.star.updateContext = function(prevType) {
if (prevType == $$tokentype$$.types._function) {
let index = this.context.length - 1
if (this.context[index] === types.f_expr)
this.context[index] = types.f_expr_gen
else
this.context[index] = types.f_gen
}
this.exprAllowed = true
}
$$tokentype$$.types.name.updateContext = function(prevType) {
let allowed = false
if (this.options.ecmaVersion >= 6) {
if (this.value == "of" && !this.exprAllowed ||
this.value == "yield" && this.inGeneratorContext())
allowed = true
}
this.exprAllowed = allowed
}
exports.TokContext = TokContext, exports.types = types;
|