From 00a9554e590dc0d5d1c08770f984bb5d2fda9f8b Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 7 Sep 2017 10:09:45 -0400 Subject: [PATCH 1/6] Test name with srcPath --- test/testFixtures.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testFixtures.ts b/test/testFixtures.ts index 0bb12749..4f17aa2c 100644 --- a/test/testFixtures.ts +++ b/test/testFixtures.ts @@ -20,7 +20,7 @@ export function callCCTest(srcPath: string, transform: string) { } it(testName, () => { - const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: ".js" }); + const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: `${srcPath}.js` }); execSync(`./bin/compile --transform ${transform} ${srcPath} ${dstPath}`); try { execSync(`./bin/run ${dstPath} --yield 1`, { timeout: 30000 }); From 7b6e86b260d3921309dfbc807d9aa1ae78f75307 Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 7 Sep 2017 10:17:13 -0400 Subject: [PATCH 2/6] Get basename for test name. --- test/testFixtures.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testFixtures.ts b/test/testFixtures.ts index 4f17aa2c..233bf6e0 100644 --- a/test/testFixtures.ts +++ b/test/testFixtures.ts @@ -20,7 +20,8 @@ export function callCCTest(srcPath: string, transform: string) { } it(testName, () => { - const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: `${srcPath}.js` }); + const basename = path.basename(srcPath, '.js') + const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: `${basename}.js` }); execSync(`./bin/compile --transform ${transform} ${srcPath} ${dstPath}`); try { execSync(`./bin/run ${dstPath} --yield 1`, { timeout: 30000 }); From a1b8a74d2baca13c8febafe46a0a85c2b7b68ac8 Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 7 Sep 2017 10:18:57 -0400 Subject: [PATCH 3/6] Also for browser tests. --- test/testFixtures.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/testFixtures.ts b/test/testFixtures.ts index 233bf6e0..06e740ac 100644 --- a/test/testFixtures.ts +++ b/test/testFixtures.ts @@ -35,6 +35,7 @@ export function callCCTest(srcPath: string, transform: string) { export function browserTest(srcPath: string, transform: string) { const testName = `${srcPath} (${transform}) (in-browser)`; + const basename = path.basename(srcPath, '.js') // Skip tests we know we can't handle if ( srcPath.indexOf("dart") >= 0 || @@ -44,8 +45,8 @@ export function browserTest(srcPath: string, transform: string) { } it(testName, () => { - const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: ".js" }); - const { name: htmlPath } = tmp.fileSync({ dir: ".", postfix: ".html" }); + const { name: dstPath } = tmp.fileSync({ dir: ".", postfix: `${basename}.js` }); + const { name: htmlPath } = tmp.fileSync({ dir: ".", postfix: `${basename}.html` }); execSync(`./bin/compile --transform ${transform} ${srcPath} ${dstPath}`); execSync(`./bin/webpack ${dstPath} ${htmlPath}`); execSync(`./bin/browser ${htmlPath} --yield 1000 --env chrome`); From 00d8286a1e12eb9186e5483080aeb0559ffc38bf Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 24 Aug 2017 16:36:31 -0400 Subject: [PATCH 4/6] flatten var at top of functions. --- src/callcc/declVars.ts | 52 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/callcc/declVars.ts b/src/callcc/declVars.ts index c5ed7e7d..8bc91295 100644 --- a/src/callcc/declVars.ts +++ b/src/callcc/declVars.ts @@ -27,7 +27,7 @@ function declToAssign(decl: t.VariableDeclarator): t.AssignmentExpression | null function getFunctionArgs(path: NodePath): string[] { const node = path.node; - if (node.type === 'FunctionDeclaration' || + if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') { return (node).params.map((x: t.Identifier) => x.name); } @@ -37,7 +37,7 @@ function getFunctionArgs(path: NodePath): string[] { } function getBlock(node: t.Node): t.Statement[] { - if (node.type === 'FunctionDeclaration' || + if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') { return (node).body.body; } @@ -49,7 +49,36 @@ function getBlock(node: t.Node): t.Statement[] { } } +const func = { + enter(path: NodePath) { + (path.node).toDecl = [] + }, + exit(path: NodePath) { + const toDecl: t.Identifier[] | undefined = (path.node).toDecl + if(toDecl && toDecl.length > 0) { + path.node.body.body.unshift(t.variableDeclaration('var', + lifted(toDecl.map(d => t.variableDeclarator(d))))) + } + } +} + +const prog = { + enter(path: NodePath) { + (path.node).toDecl = [] + }, + exit(path: NodePath) { + const toDecl: t.Identifier[] | undefined = (path.node).toDecl + if(toDecl && toDecl.length > 0) { + path.node.body.unshift(t.variableDeclaration('var', + lifted(toDecl.map(d => t.variableDeclarator(d))))) + } + } +} + const lift: Visitor = { + Program: prog, + FunctionDeclaration: func, + FunctionExpression: func, VariableDeclaration(path: NodePath>) { if (path.node.lifted) { return; @@ -73,9 +102,22 @@ const lift: Visitor = { throw new Error(`Destructuring assignment not supported`); } const id = decl.id.name; - const newDecl = t.variableDeclaration(kind, - [t.variableDeclarator(decl.id)]); - getBlock(topScope.node).unshift(lifted(newDecl)); + // This checks for the following case: + // + // function(x) { var x = 10; } + // + // is the same as: + // + // function(x) { x = 10; } + // + // Therefore, we do not need to lift x. Instead, we eliminate the + // declaration and only turn it into an assignment. + if ((kind === 'var' && topArgs.includes(id)) === false) { + (topScope.node).toDecl.push(decl.id) + //const newDecl = t.variableDeclaration(kind, + //[t.variableDeclarator(decl.id)]); + //getBlock(topScope.node).unshift(lifted(newDecl)); + } if (decl.init !== null) { // If we call path.insertAfter here, we will add assignments in reverse // order. Fortunately, path.insertAfter can take an array of nodes. From 397f52e7b672b5a6385b0f1f864e9e223ebe702a Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 7 Sep 2017 17:46:16 -0400 Subject: [PATCH 5/6] Fix lifted call. - we really need to document these --- src/callcc/declVars.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/callcc/declVars.ts b/src/callcc/declVars.ts index 8bc91295..199a259d 100644 --- a/src/callcc/declVars.ts +++ b/src/callcc/declVars.ts @@ -56,8 +56,8 @@ const func = { exit(path: NodePath) { const toDecl: t.Identifier[] | undefined = (path.node).toDecl if(toDecl && toDecl.length > 0) { - path.node.body.body.unshift(t.variableDeclaration('var', - lifted(toDecl.map(d => t.variableDeclarator(d))))) + path.node.body.body.unshift(lifted(t.variableDeclaration('var', + toDecl.map(d => t.variableDeclarator(d))))) } } } @@ -69,8 +69,8 @@ const prog = { exit(path: NodePath) { const toDecl: t.Identifier[] | undefined = (path.node).toDecl if(toDecl && toDecl.length > 0) { - path.node.body.unshift(t.variableDeclaration('var', - lifted(toDecl.map(d => t.variableDeclarator(d))))) + path.node.body.unshift(lifted(t.variableDeclaration('var', + toDecl.map(d => t.variableDeclarator(d))))) } } } @@ -113,10 +113,10 @@ const lift: Visitor = { // Therefore, we do not need to lift x. Instead, we eliminate the // declaration and only turn it into an assignment. if ((kind === 'var' && topArgs.includes(id)) === false) { - (topScope.node).toDecl.push(decl.id) //const newDecl = t.variableDeclaration(kind, //[t.variableDeclarator(decl.id)]); //getBlock(topScope.node).unshift(lifted(newDecl)); + (topScope.node).toDecl.push(decl.id) } if (decl.init !== null) { // If we call path.insertAfter here, we will add assignments in reverse From 1edb87ebbd798f260b70150adb9aa93eccead305 Mon Sep 17 00:00:00 2001 From: Rachit Nigam Date: Thu, 7 Sep 2017 17:46:50 -0400 Subject: [PATCH 6/6] Ignore vscode. I use a real editor now. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 78f962ba..53e01c08 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ demo-webpage/html/runner.js package-lock.json auth-trial/html/src-noconflict /benchmarks +.vscode