Avoid reevaluating constant portions of assertions. Avoids some repeated side-effects, e.g. +(new Date()) getting off-by-one-millisecond values.
This commit is contained in:
parent
f56cbd9ed3
commit
475355ad3d
|
@ -90,6 +90,7 @@ function astifySyndicatePath(state, a) {
|
||||||
|
|
||||||
function compilePattern(state, patternPath) {
|
function compilePattern(state, patternPath) {
|
||||||
let constPaths = [];
|
let constPaths = [];
|
||||||
|
let constTemps = [];
|
||||||
let constVals = [];
|
let constVals = [];
|
||||||
let capturePaths = [];
|
let capturePaths = [];
|
||||||
let captureIds = [];
|
let captureIds = [];
|
||||||
|
@ -102,7 +103,10 @@ function compilePattern(state, patternPath) {
|
||||||
|
|
||||||
function pushConstant(node) {
|
function pushConstant(node) {
|
||||||
constPaths.push(syndicatePath.slice());
|
constPaths.push(syndicatePath.slice());
|
||||||
constVals.push(node);
|
const id = patternPath.scope.generateUidIdentifier('c' + constTemps.length);
|
||||||
|
constTemps.push([id, node]);
|
||||||
|
constVals.push(id);
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function walk(patternPath) {
|
function walk(patternPath) {
|
||||||
|
@ -134,8 +138,7 @@ function compilePattern(state, patternPath) {
|
||||||
}
|
}
|
||||||
return [t.arrayExpression(skel), t.callExpression(cloneDeep(pattern.callee), assn)];
|
return [t.arrayExpression(skel), t.callExpression(cloneDeep(pattern.callee), assn)];
|
||||||
} else {
|
} else {
|
||||||
pushConstant(pattern);
|
return [t.nullLiteral(), pushConstant(pattern)];
|
||||||
return [t.nullLiteral(), pattern];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +150,7 @@ function compilePattern(state, patternPath) {
|
||||||
pushCapture(pattern);
|
pushCapture(pattern);
|
||||||
return [t.nullLiteral(), captureWrap(state, discardAst(state))];
|
return [t.nullLiteral(), captureWrap(state, discardAst(state))];
|
||||||
} else {
|
} else {
|
||||||
pushConstant(pattern);
|
return [t.nullLiteral(), pushConstant(pattern)];
|
||||||
return [t.nullLiteral(), pattern];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'ArrayExpression': {
|
case 'ArrayExpression': {
|
||||||
|
@ -165,8 +167,7 @@ function compilePattern(state, patternPath) {
|
||||||
}
|
}
|
||||||
return [t.arrayExpression(skel), t.arrayExpression(assn)];
|
return [t.arrayExpression(skel), t.arrayExpression(assn)];
|
||||||
} else {
|
} else {
|
||||||
pushConstant(pattern);
|
return [t.nullLiteral(), pushConstant(pattern)];
|
||||||
return [t.nullLiteral(), pattern];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +177,7 @@ function compilePattern(state, patternPath) {
|
||||||
}
|
}
|
||||||
// FALL THROUGH
|
// FALL THROUGH
|
||||||
case 'MemberExpression':
|
case 'MemberExpression':
|
||||||
pushConstant(pattern);
|
return [t.nullLiteral(), pushConstant(pattern)];
|
||||||
return [t.nullLiteral(), pattern];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@ function compilePattern(state, patternPath) {
|
||||||
return {
|
return {
|
||||||
skeletonAst: skeleton,
|
skeletonAst: skeleton,
|
||||||
constPathsAst: astifySyndicatePath(state, constPaths),
|
constPathsAst: astifySyndicatePath(state, constPaths),
|
||||||
|
constTemps: constTemps,
|
||||||
constValsAst: listAst(state, t.arrayExpression(constVals)),
|
constValsAst: listAst(state, t.arrayExpression(constVals)),
|
||||||
capturePathsAst: astifySyndicatePath(state, capturePaths),
|
capturePathsAst: astifySyndicatePath(state, capturePaths),
|
||||||
captureIds: captureIds,
|
captureIds: captureIds,
|
||||||
|
@ -248,6 +249,7 @@ function translateEndpoint(state, path, expectedEvt) {
|
||||||
|
|
||||||
path.replaceWith(template(
|
path.replaceWith(template(
|
||||||
`DATASPACE._currentFacet.addEndpoint(function () {
|
`DATASPACE._currentFacet.addEndpoint(function () {
|
||||||
|
CONSTTEMPS;
|
||||||
let HANDLER = {
|
let HANDLER = {
|
||||||
skeleton: SKELETON,
|
skeleton: SKELETON,
|
||||||
constPaths: CONSTPATHS,
|
constPaths: CONSTPATHS,
|
||||||
|
@ -268,6 +270,7 @@ function translateEndpoint(state, path, expectedEvt) {
|
||||||
HANDLER: path.scope.generateUidIdentifier("handler"),
|
HANDLER: path.scope.generateUidIdentifier("handler"),
|
||||||
SKELETON: info.skeletonAst,
|
SKELETON: info.skeletonAst,
|
||||||
CONSTPATHS: info.constPathsAst,
|
CONSTPATHS: info.constPathsAst,
|
||||||
|
CONSTTEMPS: info.constTemps.map(([n,i]) => template(`const N = I;`)({N:n, I:i})),
|
||||||
CONSTVALS: info.constValsAst,
|
CONSTVALS: info.constValsAst,
|
||||||
CAPTUREPATHS: info.capturePathsAst,
|
CAPTUREPATHS: info.capturePathsAst,
|
||||||
EVT: _evt,
|
EVT: _evt,
|
||||||
|
|
Loading…
Reference in New Issue