@agoric/acorn-eventual-send
Advanced tools
Comparing version 1.0.2 to 2.0.0
249
index.js
@@ -1,7 +0,1 @@ | ||
const { tokTypes: tt, TokenType, Parser: AcornParser } = require('acorn'); | ||
const tok = { | ||
tildeDot: new TokenType('~.'), | ||
}; | ||
const tilde = '~'.charCodeAt(0); | ||
@@ -11,134 +5,140 @@ const dot = '.'.charCodeAt(0); | ||
const nine = '9'.charCodeAt(0); | ||
function plugin(options, Parser) { | ||
return class extends Parser { | ||
// eslint-disable-next-line camelcase | ||
readToken_tilde() { | ||
const next1 = this.input.charCodeAt(this.start + 1); | ||
const next2 = this.input.charCodeAt(this.start + 2); | ||
if (next1 === dot && !(next2 >= zero && next2 <= nine)) { | ||
this.pos += 2; | ||
return this.finishToken(tok.tildeDot); | ||
} | ||
return this.finishOp(tt.prefix, 1); | ||
} | ||
getTokenFromCode(code) { | ||
if (code === tilde) { | ||
return this.readToken_tilde(); | ||
function makeCurryOptions(acorn, options = {}) { | ||
const { tokTypes: tt, TokenType } = acorn; | ||
const tok = { | ||
tildeDot: new TokenType('~.'), | ||
}; | ||
function plugin(options, Parser) { | ||
return class extends Parser { | ||
// eslint-disable-next-line camelcase | ||
readToken_tilde() { | ||
const next1 = this.input.charCodeAt(this.start + 1); | ||
const next2 = this.input.charCodeAt(this.start + 2); | ||
if (next1 === dot && !(next2 >= zero && next2 <= nine)) { | ||
this.pos += 2; | ||
return this.finishToken(tok.tildeDot); | ||
} | ||
return this.finishOp(tt.prefix, 1); | ||
} | ||
return super.getTokenFromCode(code); | ||
} | ||
parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) { | ||
if (!this.eat(tok.tildeDot)) { | ||
return super.parseSubscript( | ||
base, | ||
startPos, | ||
startLoc, | ||
noCalls, | ||
maybeAsyncArrow, | ||
); | ||
getTokenFromCode(code) { | ||
if (code === tilde) { | ||
return this.readToken_tilde(); | ||
} | ||
return super.getTokenFromCode(code); | ||
} | ||
const HANDLED_PROMISE = options.HandledPromise; | ||
const node = this.startNodeAt(startPos, startLoc); | ||
parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow) { | ||
if (!this.eat(tok.tildeDot)) { | ||
return super.parseSubscript( | ||
base, | ||
startPos, | ||
startLoc, | ||
noCalls, | ||
maybeAsyncArrow, | ||
); | ||
} | ||
// Do HandledPromise.METHOD(BASE, ...) | ||
let method; | ||
const args = [base]; | ||
let eatenParenL = false; | ||
if (this.eat(tt.bracketL)) { | ||
// x ~. [i]... | ||
// The second argument is always the computed expression. | ||
args.push(this.parseExpression()); | ||
this.expect(tt.bracketR); | ||
} else if (this.eat(tt.parenL)) { | ||
// x ~. (y, z) := HandledPromise.applyFunction(base, [y, z]) | ||
// No argument other than base. | ||
eatenParenL = true; | ||
} else { | ||
// Simple case: x ~. p... | ||
// Second argument is stringified identifier. | ||
const property = this.parseIdentifier(); | ||
let arg = this.startNodeAtNode(property); | ||
arg.value = property.name; | ||
arg = this.finishNode(arg, 'Literal'); | ||
args.push(arg); | ||
} | ||
if (eatenParenL || this.eat(tt.parenL)) { | ||
// x ~. [i](y, z) := HandledPromise.applyMethod(base, i, [y, z]) | ||
// x ~. (y, z) := HandledPromise.applyFunction(base, [y, z]); | ||
method = eatenParenL ? 'applyFunction' : 'applyMethod'; | ||
// The rest of the arguments are in parens. | ||
let expr = this.startNode(); | ||
expr.elements = this.parseCallExpressionArguments(tt.parenR, false); | ||
expr = this.finishNode(expr, 'ArrayExpression'); | ||
args.push(expr); | ||
} else if (this.eat(tt.eq)) { | ||
// x ~. [i] = foo := HandledPromise.set(base, i) | ||
method = 'set'; | ||
args.push(this.parseMaybeAssign()); | ||
} else { | ||
// x ~. [i] := HandledPromise.get(base, i) | ||
// Method may change to HandledPromise.delete(base, i) | ||
method = 'get'; | ||
} | ||
const HANDLED_PROMISE = options.HandledPromise; | ||
const node = this.startNodeAt(startPos, startLoc); | ||
let callee = this.startNodeAtNode(node); | ||
callee.object = this.createIdentifier( | ||
this.startNodeAtNode(node), | ||
HANDLED_PROMISE, | ||
); | ||
callee.property = this.createIdentifier( | ||
this.startNodeAtNode(node), | ||
method, | ||
); | ||
callee.computed = false; | ||
callee = this.finishNode(callee, 'MemberExpression'); | ||
// Do HandledPromise.METHOD(BASE, ...) | ||
let method; | ||
const args = [base]; | ||
let eatenParenL = false; | ||
if (this.eat(tt.bracketL)) { | ||
// x ~. [i]... | ||
// The second argument is always the computed expression. | ||
args.push(this.parseExpression()); | ||
this.expect(tt.bracketR); | ||
} else if (this.eat(tt.parenL)) { | ||
// x ~. (y, z) := HandledPromise.applyFunction(base, [y, z]) | ||
// No argument other than base. | ||
eatenParenL = true; | ||
} else { | ||
// Simple case: x ~. p... | ||
// Second argument is stringified identifier. | ||
const property = this.parseIdentifier(); | ||
let arg = this.startNodeAtNode(property); | ||
arg.value = property.name; | ||
arg = this.finishNode(arg, 'Literal'); | ||
args.push(arg); | ||
} | ||
if (eatenParenL || this.eat(tt.parenL)) { | ||
// x ~. [i](y, z) := HandledPromise.applyMethod(base, i, [y, z]) | ||
// x ~. (y, z) := HandledPromise.applyFunction(base, [y, z]); | ||
method = eatenParenL ? 'applyFunction' : 'applyMethod'; | ||
// The rest of the arguments are in parens. | ||
let expr = this.startNode(); | ||
expr.elements = this.parseCallExpressionArguments(tt.parenR, false); | ||
expr = this.finishNode(expr, 'ArrayExpression'); | ||
args.push(expr); | ||
} else if (this.eat(tt.eq)) { | ||
// x ~. [i] = foo := HandledPromise.set(base, i) | ||
method = 'set'; | ||
args.push(this.parseMaybeAssign()); | ||
} else { | ||
// x ~. [i] := HandledPromise.get(base, i) | ||
// Method may change to HandledPromise.delete(base, i) | ||
method = 'get'; | ||
} | ||
// Create a WavyDot CallExpression. | ||
const wdot = this.startNodeAtNode(node); | ||
if (method === 'get') { | ||
wdot.maybeDeleteWavyDot = true; | ||
let callee = this.startNodeAtNode(node); | ||
callee.object = this.createIdentifier( | ||
this.startNodeAtNode(node), | ||
HANDLED_PROMISE, | ||
); | ||
callee.property = this.createIdentifier( | ||
this.startNodeAtNode(node), | ||
method, | ||
); | ||
callee.computed = false; | ||
callee = this.finishNode(callee, 'MemberExpression'); | ||
// Create a WavyDot CallExpression. | ||
const wdot = this.startNodeAtNode(node); | ||
if (method === 'get') { | ||
wdot.maybeDeleteWavyDot = true; | ||
} | ||
wdot.callee = callee; | ||
wdot.arguments = args; | ||
return this.finishNode(wdot, 'CallExpression'); | ||
} | ||
wdot.callee = callee; | ||
wdot.arguments = args; | ||
return this.finishNode(wdot, 'CallExpression'); | ||
} | ||
parseMaybeUnary(refDestructuringErrors, sawUnary) { | ||
const node = super.parseMaybeUnary(refDestructuringErrors, sawUnary); | ||
if (node.operator === 'delete' && node.argument.maybeDeleteWavyDot) { | ||
const arg = node.argument; | ||
delete arg.maybeDeleteWavyDot; | ||
let deleteId = this.startNodeAtNode(node); | ||
deleteId = this.createIdentifier(deleteId, 'delete'); | ||
arg.callee.property = deleteId; | ||
return arg; | ||
parseMaybeUnary(refDestructuringErrors, sawUnary) { | ||
const node = super.parseMaybeUnary(refDestructuringErrors, sawUnary); | ||
if (node.operator === 'delete' && node.argument.maybeDeleteWavyDot) { | ||
const arg = node.argument; | ||
delete arg.maybeDeleteWavyDot; | ||
let deleteId = this.startNodeAtNode(node); | ||
deleteId = this.createIdentifier(deleteId, 'delete'); | ||
arg.callee.property = deleteId; | ||
return arg; | ||
} | ||
return node; | ||
} | ||
return node; | ||
} | ||
// Helper functions from Babel... | ||
startNodeAtNode(node) { | ||
return this.startNodeAt(node.startPos, node.startLoc); | ||
} | ||
// Helper functions from Babel... | ||
startNodeAtNode(node) { | ||
return this.startNodeAt(node.startPos, node.startLoc); | ||
} | ||
createIdentifier(node, ident) { | ||
node.name = ident; | ||
return this.finishNode(node, 'Identifier'); | ||
} | ||
createIdentifier(node, ident) { | ||
node.name = ident; | ||
return this.finishNode(node, 'Identifier'); | ||
} | ||
parseIdentifier() { | ||
return this.parseIdent(true); | ||
} | ||
parseIdentifier() { | ||
return this.parseIdent(true); | ||
} | ||
parseCallExpressionArguments(endToken, bool) { | ||
return this.parseExprList(endToken, true, bool); | ||
} | ||
}; | ||
} | ||
parseCallExpressionArguments(endToken, bool) { | ||
return this.parseExprList(endToken, true, bool); | ||
} | ||
}; | ||
} | ||
module.exports = function curryOptions(options) { | ||
options = options || {}; | ||
return function extendParser(Parser) { | ||
@@ -152,5 +152,4 @@ return plugin( | ||
}; | ||
}; | ||
module.exports.tokTypes = tok; | ||
module.exports.Parser = AcornParser; | ||
} | ||
module.exports = makeCurryOptions; |
{ | ||
"name": "@agoric/acorn-eventual-send", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Eventual send (wavy dot) parser plugin for Acorn", | ||
@@ -12,2 +12,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"acorn": "^6.2.0", | ||
"eslint": "^5.11.1", | ||
@@ -27,5 +28,2 @@ "eslint-config-airbnb": "^17.1.0", | ||
}, | ||
"dependencies": { | ||
"acorn": "^6.2.0" | ||
}, | ||
"keywords": [], | ||
@@ -37,3 +35,3 @@ "files": [ | ||
"type": "git", | ||
"url": "https://github.com/Agoric/acorn-infix-bang" | ||
"url": "https://github.com/Agoric/acorn-eventual-send" | ||
}, | ||
@@ -43,5 +41,5 @@ "author": "Agoric", | ||
"bugs": { | ||
"url": "https://github.com/Agoric/acorn-infix-bang/issues" | ||
"url": "https://github.com/Agoric/acorn-eventual-send/issues" | ||
}, | ||
"homepage": "https://github.com/acorn-infix-bang#readme" | ||
"homepage": "https://github.com/acorn-eventual-send#readme" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
17575
0
14
137
- Removedacorn@^6.2.0
- Removedacorn@6.4.2(transitive)