mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-09-06 15:07:21 +00:00
push all website files
This commit is contained in:
13
website/functions/node_modules/acorn-es7-plugin/test/babel.js
generated
vendored
Normal file
13
website/functions/node_modules/acorn-es7-plugin/test/babel.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
// If this doesn't throw, then arrow functions are supported natively.
|
||||
// Do not require babel (for speed).
|
||||
eval('var x = () => {};');
|
||||
} catch (e) {
|
||||
require('babel-core/register')({
|
||||
only: /test.js$/,
|
||||
presets: ['es2015']
|
||||
});
|
||||
}
|
||||
|
1
website/functions/node_modules/acorn-es7-plugin/test/mocha.opts
generated
vendored
Normal file
1
website/functions/node_modules/acorn-es7-plugin/test/mocha.opts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
--compilers js:babel.js
|
42
website/functions/node_modules/acorn-es7-plugin/test/package.json
generated
vendored
Normal file
42
website/functions/node_modules/acorn-es7-plugin/test/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "acorn-es7-plugin-test",
|
||||
"version": "0.0.5",
|
||||
"description": "Tests for acorn-es7-plugin",
|
||||
"main": "nothing-here",
|
||||
"scripts": {
|
||||
"test": "npm i acorn@3 ; mocha --opts ./mocha.opts ; node test-es5.js ; npm i acorn@4 ; mocha --opts ./mocha.opts ; node test-es5.js ; npm i acorn@5 ; mocha --opts ./mocha.opts ; node test-es5.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/MatAtBread/acorn-es7-plugin.git"
|
||||
},
|
||||
"keywords": [
|
||||
"acorn",
|
||||
"parser",
|
||||
"es7",
|
||||
"async",
|
||||
"await"
|
||||
],
|
||||
"author": "matatbread",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/MatAtBread/acorn-es7-plugin/issues"
|
||||
},
|
||||
"homepage": "https://github.com/MatAtBread/acorn-es7-plugin#readme",
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.0.20",
|
||||
"babel-preset-es2015": "^6.0.15",
|
||||
"estraverse": "^4.1.1",
|
||||
"mocha": "^2.3.3",
|
||||
"colors": "^1.1.2",
|
||||
"xtend": "^4.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-core": "^6.14.0",
|
||||
"babel-preset-es2015": "^6.14.0",
|
||||
"colors": "^1.1.2",
|
||||
"estraverse": "^4.2.0",
|
||||
"mocha": "^2.5.3",
|
||||
"xtend": "^4.0.1"
|
||||
}
|
||||
}
|
396
website/functions/node_modules/acorn-es7-plugin/test/test-es5.js
generated
vendored
Normal file
396
website/functions/node_modules/acorn-es7-plugin/test/test-es5.js
generated
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
'use strict';
|
||||
/* Simple test script that doesn't need mocha or similar - it just parses stuff and checks the returned AST */
|
||||
var acorn = require('acorn');
|
||||
var colors = require('colors');
|
||||
require('../')(acorn);
|
||||
function parse(code, pluginOptions, scriptType) {
|
||||
if (Array.isArray(code)) {
|
||||
code = code.join('\n');
|
||||
}
|
||||
return acorn.parse(code, {
|
||||
sourceType: scriptType,
|
||||
ecmaVersion: 8,
|
||||
locations: true,
|
||||
ranges: true,
|
||||
plugins: {
|
||||
asyncawait: pluginOptions || {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isIdentThenFnDecl(ast) {
|
||||
return ast.body[0].type === 'ExpressionStatement' && ast.body[0].expression.type === 'Identifier' && ast.body[0].expression.name === 'async' && !ast.body[1].async === true && ast.body[1].type == "FunctionDeclaration";
|
||||
}
|
||||
|
||||
function isAsyncFnDecl(ast) {
|
||||
return ast.body[0].async === true && ast.body[0].type === "FunctionDeclaration";
|
||||
}
|
||||
|
||||
function isAsyncFnExpr(ast) {
|
||||
return ast.body[0].expression.async === true && ast.body[0].expression.type === "ArrowFunctionExpression";
|
||||
}
|
||||
|
||||
function isExprType(type) {
|
||||
return function (ast, sourceType) {
|
||||
return ast.body[0].type === 'ExpressionStatement' && ast.body[0].expression.type === type;
|
||||
};
|
||||
}
|
||||
|
||||
var tests = [
|
||||
/* Standard behaviours */
|
||||
{
|
||||
desc: "Simple async function",
|
||||
code: "async function x() { return undefined; }",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].async === true;
|
||||
}
|
||||
},{
|
||||
desc: "Simple async function expression",
|
||||
code: "(async function (){ })",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].expression.async === true;
|
||||
}
|
||||
},{
|
||||
desc: "Async function expression call (1)",
|
||||
code: "(async function (){ }())",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].expression.callee.async === true;
|
||||
}
|
||||
},{
|
||||
desc: "Async function expression call (2)",
|
||||
code: "(async function (){ })()",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].expression.callee.async === true;
|
||||
}
|
||||
},{
|
||||
desc: "Await in async is AwaitExpression",
|
||||
code: "async function x() { await(undefined); await undefined ; }",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].expression.type === 'AwaitExpression' && ast.body[0].body.body[1].expression.type === 'AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Await in function is identifier in 'script', illegal in 'module'",
|
||||
code: "function x() { await(undefined); }",
|
||||
pass: function (ast,scriptType) {
|
||||
return scriptType === 'script'?ast.body[0].body.body[0].expression.callee.name === 'await':ast.indexOf("(1:15)")>=0;
|
||||
}
|
||||
},{
|
||||
desc: "Async method {code}",
|
||||
code: "var a = {async x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.properties[0].value.async;
|
||||
}
|
||||
},{
|
||||
desc: "Async arrow",
|
||||
code: "var a = async()=>0",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.async;
|
||||
}
|
||||
},{
|
||||
desc: "Abbreviated async arrow",
|
||||
code: "var a = async b=>-b",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.async;
|
||||
}
|
||||
},{
|
||||
desc: "Parenthesized async arrow is a call",
|
||||
code: "var a = async(b=>0)",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.type==='CallExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Await declaration fails in async function",
|
||||
code: "async function x() { var await; }",
|
||||
pass: function (ex, scriptType) {
|
||||
return ex.indexOf("(1:25)")>=0
|
||||
}
|
||||
},{
|
||||
desc: "Await function declaration fails in async function",
|
||||
code: "async function x() { function await() {} }",
|
||||
pass: function (ex, scriptType) {
|
||||
return ex.indexOf("(1:30)")>=0
|
||||
}
|
||||
},{
|
||||
desc: "Await reference fails in async function",
|
||||
code: "async function x() { return 1+await; }",
|
||||
pass: function (ex) {
|
||||
return !!ex.match(/\(1:3[05]\)/);
|
||||
}
|
||||
},{
|
||||
desc: "{code} is an async FunctionExpression",
|
||||
code: "async ()=>0",
|
||||
pass: isAsyncFnExpr
|
||||
},{
|
||||
desc: "{code} is a CallExpression",
|
||||
code: "async(()=>0)",
|
||||
pass: isExprType('CallExpression')
|
||||
},{
|
||||
desc: "{code} is an async FunctionDeclaration",
|
||||
code: "async /* a */ function x(){}",
|
||||
pass: isAsyncFnDecl
|
||||
},{
|
||||
desc: "{code} is a reference to 'async' and a sync FunctionDeclaration",
|
||||
code: "async /*\n*/function x(){}",
|
||||
pass: isIdentThenFnDecl
|
||||
},{
|
||||
desc: "{code} is a reference to 'async' and a sync FunctionDeclaration",
|
||||
code: "async /* a */\nfunction x(){}",
|
||||
pass: isIdentThenFnDecl
|
||||
},{
|
||||
desc: "{code} is a reference to 'async' and a sync FunctionDeclaration",
|
||||
code: "async\nfunction x(){}",
|
||||
pass: isIdentThenFnDecl
|
||||
},{
|
||||
desc: "{code} is a reference to 'async' and a sync FunctionDeclaration",
|
||||
code: "async //\nfunction x(){}",
|
||||
pass: isIdentThenFnDecl
|
||||
},{
|
||||
desc: "{code} is a reference to 'async' and a sync FunctionDeclaration",
|
||||
code: "async /*\n*/\nfunction x(){}",
|
||||
pass: isIdentThenFnDecl
|
||||
},{
|
||||
desc: "{code} is a SyntaxError (when inAsyncFunction and awaitAnywhere option are defaults)",
|
||||
code: "await x",
|
||||
pass: function (ex, sourceType) {
|
||||
return sourceType==='module' ? !!ex.match(/\(1:0\)/) : ex === "Unexpected token (1:6)";
|
||||
}
|
||||
},{
|
||||
desc: "{code} is a CallExpression in scripts, and a SyntaxError in modules",
|
||||
code: "await(x)",
|
||||
pass: function(ast,sourceType) {
|
||||
return sourceType==='module'?!!ast.match(/\(1:0\)/) :isExprType('CallExpression')(ast)
|
||||
}
|
||||
},{
|
||||
desc: "Async method 'constructor' is valid",
|
||||
code: "var a = {async constructor(){}}",
|
||||
pass: function (ast) {
|
||||
var props = ast.body[0].declarations[0].init.properties ;
|
||||
return (props[0].kind === 'init' && props[0].key.name==='constructor' && props[0].value.async)
|
||||
}
|
||||
},{
|
||||
desc: "Async class constructor fails",
|
||||
code: "class a {async constructor(){}}",
|
||||
pass: function (ex) {
|
||||
return !!ex.match(/class constructor\(\) cannot be be async \(1:(15|9)\)/) || ex === "Constructor can't be an async method (1:15)";
|
||||
}
|
||||
},{
|
||||
desc: "Async setter fails",
|
||||
code: "var a = {async set x(y){}}",
|
||||
pass: function (ex) {
|
||||
return ex === "'set <member>(value)' cannot be be async (1:15)" || ex === "Unexpected token (1:19)";
|
||||
}
|
||||
},{
|
||||
desc: "Deprecated async setter fails (use 'async set x')",
|
||||
code: "var a = {set async x(y){}}",
|
||||
pass: function (ex) {
|
||||
return ex === "'set <member>(value)' cannot be be async (1:13)" || ex === "Unexpected token (1:19)";
|
||||
}
|
||||
},{
|
||||
desc: "{code} getters/setters are not async",
|
||||
code: "var a = {get x(){},set y(z){}}",
|
||||
pass: function (ast) {
|
||||
var props = ast.body[0].declarations[0].init.properties ;
|
||||
return (props[0].kind === 'get' && props[0].key.name==='x' && !props[0].value.async)
|
||||
&& (props[1].kind === 'set' && props[1].key.name==='y' && !props[1].value.async);
|
||||
}
|
||||
},{
|
||||
desc: "{code} are methods, not getters/setters",
|
||||
code: "var a = {async get(){},async set(){}}",
|
||||
pass: function (ast) {
|
||||
var props = ast.body[0].declarations[0].init.properties ;
|
||||
return (props[0].kind === 'init' && props[0].key.name==='get' && props[0].value.async)
|
||||
&& (props[1].kind === 'init' && props[1].key.name==='set' && props[1].value.async);
|
||||
}
|
||||
},{
|
||||
desc: "In {code}, x is an sync getter",
|
||||
code: "class a {get x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].kind==="get" && !ast.body[0].body.body[0].value.async && !ast.body[0].body.body[0].static ;
|
||||
}
|
||||
},{
|
||||
desc: "In {code}, x is an static sync getter",
|
||||
code: "class a {static get x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].kind==="get" && !ast.body[0].body.body[0].value.async && ast.body[0].body.body[0].static ;
|
||||
}
|
||||
},{
|
||||
desc: "In {code}, x is an static sync method",
|
||||
code: "class a {static async x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].kind==="method" && ast.body[0].body.body[0].value.async && ast.body[0].body.body[0].static ;
|
||||
}
|
||||
},{
|
||||
desc: "{code} are a getters/setters, not methods",
|
||||
code: "var a = {get async(){},set async(x){}}",
|
||||
pass: function (ast) {
|
||||
var props = ast.body[0].declarations[0].init.properties ;
|
||||
return (props[0].kind === 'get' && props[0].key.name==='async' && !props[0].value.async)
|
||||
&& (props[1].kind === 'set' && props[1].key.name==='async' && !props[1].value.async);
|
||||
}
|
||||
},
|
||||
/* Extended syntax behaviour for Nodent */
|
||||
{
|
||||
desc: "Nodent:".grey+" In {code}, get is a static method",
|
||||
code: "class Foo { static get(v) {} }",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].type==='MethodDefinition'
|
||||
&& ast.body[0].body.body[0].key.name === 'get'
|
||||
&& ast.body[0].body.body[0].kind === "method"
|
||||
&& ast.body[0].body.body[0].static;
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, get is a non-static method",
|
||||
code: "class Foo { get(v) {} }",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].type==='MethodDefinition'
|
||||
&& ast.body[0].body.body[0].key.name === 'get'
|
||||
&& ast.body[0].body.body[0].kind === "method"
|
||||
&& !ast.body[0].body.body[0].static;
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, get is a non-static getter",
|
||||
code: "class Foo { get get() {} }",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].type==='MethodDefinition'
|
||||
&& ast.body[0].body.body[0].key.name === 'get'
|
||||
&& ast.body[0].body.body[0].kind === "get"
|
||||
&& !ast.body[0].body.body[0].static;
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, x is an async getter",
|
||||
code: "var a = {async get x(){ await(0) }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.properties[0].value.async
|
||||
&& ast.body[0].declarations[0].init.properties[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code} (deprecated), x is an async getter",
|
||||
code: "var a = {get async x(){ await 0 }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.properties[0].value.async
|
||||
&& ast.body[0].declarations[0].init.properties[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code} (deprecated), x is an async getter",
|
||||
code: "var a = {get async x(){ await(0) }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].declarations[0].init.properties[0].value.async
|
||||
&& ast.body[0].declarations[0].init.properties[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, x is an async getter",
|
||||
code: "class a {async get x(){ await 0 }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].value.async
|
||||
&& ast.body[0].body.body[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, x is an async getter",
|
||||
code: "class a {async get x(){ await(0) }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].value.async
|
||||
&& ast.body[0].body.body[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code} (deprecated), x is an async getter",
|
||||
code: "class a {get async x(){ await 0 }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].value.async
|
||||
&& ast.body[0].body.body[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code} (deprecated), x is an async getter",
|
||||
code: "class a {get async x(){ await(0) }}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].value.async
|
||||
&& ast.body[0].body.body[0].value.body.body[0].expression.type==='AwaitExpression';
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code}, x is an static async getter",
|
||||
code: "class a {static async get x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].kind==="get" && ast.body[0].body.body[0].value.async && ast.body[0].body.body[0].static ;
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" In {code} (deprecated), x is an static async getter",
|
||||
code: "class a {static get async x(){}}",
|
||||
pass: function (ast) {
|
||||
return ast.body[0].body.body[0].kind==="get" && ast.body[0].body.body[0].value.async && ast.body[0].body.body[0].static ;
|
||||
}
|
||||
},{
|
||||
desc: "Nodent:".grey+" {code} is an AwaitExpression when inAsyncFunction option is true",
|
||||
code: "await(x)",
|
||||
options: {
|
||||
inAsyncFunction: true
|
||||
},
|
||||
pass: isExprType('AwaitExpression')
|
||||
},{
|
||||
desc: "Nodent:".grey+" {code} is an AwaitExpression when inAsyncFunction option is true",
|
||||
code: "await x",
|
||||
options: {
|
||||
inAsyncFunction: true
|
||||
},
|
||||
pass: isExprType('AwaitExpression')
|
||||
},{
|
||||
desc: "Nodent:".grey+" {code} is a CallExpression when awaitAnywhere option is true",
|
||||
code: "await(x)",
|
||||
options: {
|
||||
awaitAnywhere: true
|
||||
},
|
||||
pass: isExprType('CallExpression')
|
||||
},{
|
||||
desc: "Nodent:".grey+" {code} is an AwaitExpression when awaitAnywhere option is true",
|
||||
code: "await x",
|
||||
options: {
|
||||
awaitAnywhere: true
|
||||
},
|
||||
pass: isExprType('AwaitExpression')
|
||||
}];
|
||||
// TODO: Add tests for asyncExits, noAsyncGetters
|
||||
|
||||
var out = {
|
||||
true: "pass".green,
|
||||
false: "fail".red
|
||||
};
|
||||
var testNumber = +process.argv[2] || 0;
|
||||
if (testNumber) {
|
||||
tests = [tests[testNumber - 1]];
|
||||
} else {
|
||||
testNumber += 1;
|
||||
}
|
||||
var results = {
|
||||
true: 0,
|
||||
false: 0
|
||||
};
|
||||
|
||||
tests.forEach(function (test, idx) {
|
||||
['script','module'].forEach(function(scriptType){
|
||||
var code = test.code.replace(/\n/g, ' <linefeed> ');
|
||||
var desc = test.desc.replace('{code}', code.yellow);
|
||||
var pass = function () {
|
||||
var p = test.pass.apply(this, arguments);
|
||||
results[p] += 1;
|
||||
return p;
|
||||
};
|
||||
var prefix = idx + testNumber + " (" + scriptType + ", acorn v" + acorn.version+")\t" ;
|
||||
try {
|
||||
console.log(prefix, desc, out[pass(parse(test.code, test.options, scriptType),scriptType)]);
|
||||
} catch (ex) {
|
||||
try {
|
||||
console.log(prefix, desc, ex.message.cyan, out[pass(ex.message,scriptType)]);
|
||||
} catch (ex) {
|
||||
console.log(prefix, desc, ex.message.magenta, out[false]);
|
||||
results.false += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
}) ;
|
||||
console.log('');
|
||||
if (results.true)
|
||||
console.log((results.true + " of " + tests.length*2 + " tests passed").green);
|
||||
if (results.false) {
|
||||
console.log((results.false + " of " + tests.length*2 + " tests failed").red);
|
||||
var exit = new Error("Test failed") ;
|
||||
exit.stack = "" ;
|
||||
throw exit ;
|
||||
}
|
590
website/functions/node_modules/acorn-es7-plugin/test/test.js
generated
vendored
Normal file
590
website/functions/node_modules/acorn-es7-plugin/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,590 @@
|
||||
'use strict';
|
||||
|
||||
var acorn = require('acorn');
|
||||
require('../')(acorn);
|
||||
var estraverse = require('estraverse');
|
||||
var xtend = require('xtend');
|
||||
var assert = require('assert');
|
||||
|
||||
function find (type, ast, skip) {
|
||||
skip = skip || 0;
|
||||
var skipped = 0;
|
||||
|
||||
var found;
|
||||
|
||||
estraverse.traverse(ast, {
|
||||
enter: (node) => {
|
||||
if (found) {
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
if (node.type == type) {
|
||||
if (skipped === skip) {
|
||||
found = node;
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
skipped++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
throw new Error('did not find AwaitExpression (skipped ' + skipped + '/' + skip + ')');
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
function extendOptions(pluginOptions, acornOptions) {
|
||||
return xtend({
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 8,
|
||||
locations: true,
|
||||
ranges: true,
|
||||
plugins: {asyncawait: pluginOptions || pluginOptions !== false}
|
||||
}, acornOptions);
|
||||
}
|
||||
|
||||
function parse(code, pluginOptions, acornOptions) {
|
||||
if (Array.isArray(code)) {
|
||||
code = code.join('\n');
|
||||
}
|
||||
var options = extendOptions(pluginOptions, acornOptions);
|
||||
return acorn.parse(code, options);
|
||||
}
|
||||
|
||||
describe('async', () => {
|
||||
describe ('function declaration', () => {
|
||||
var node;
|
||||
|
||||
describe('-', () => {
|
||||
beforeEach(() => {
|
||||
node = find(
|
||||
'FunctionDeclaration',
|
||||
parse([
|
||||
'async function foo() {',
|
||||
' x = await bar()',
|
||||
'}'
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('marks the node as async', () =>
|
||||
assert(node.async)
|
||||
);
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 0)
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, 42)
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 1,
|
||||
column: 0
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 3,
|
||||
column: 1
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
var assertFindsIdentifierExpressionStatement = (ast) => {
|
||||
node = find('ExpressionStatement', ast);
|
||||
assert.strictEqual(node.expression.type, 'Identifier');
|
||||
assert.strictEqual(node.expression.name, 'async');
|
||||
assert.deepEqual(node.expression.loc, {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 5
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
describe('linefeed after async (simple)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'async \t\t ',
|
||||
'function foo() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierExpressionStatement(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionDeclaration as async', () => {
|
||||
node = find('FunctionDeclaration', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (single line comment)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'async // flag enables async completion',
|
||||
'function foo() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierExpressionStatement(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionDeclaration as async', () => {
|
||||
node = find('FunctionDeclaration', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (multiline comment) function', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'async /* flag enables async completion',
|
||||
' of the callback */function foo() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierExpressionStatement(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionDeclaration as async', () => {
|
||||
node = find('FunctionDeclaration', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe ('function expression', () => {
|
||||
var node, code;
|
||||
|
||||
describe('-', () => {
|
||||
beforeEach(() => {
|
||||
code = [
|
||||
'foo = async function () {',
|
||||
' x = await bar()',
|
||||
'}'
|
||||
];
|
||||
node = find(
|
||||
'FunctionExpression',
|
||||
parse(code)
|
||||
);
|
||||
});
|
||||
|
||||
it('marks the node as async', () =>
|
||||
assert(node.async)
|
||||
);
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 6)
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, code.join('\n').length)
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 1,
|
||||
column: 6
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 3,
|
||||
column: 1
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
var assertFindsIdentifierAssignmentExpressionRHS = (ast) => {
|
||||
node = find('AssignmentExpression', ast);
|
||||
assert.strictEqual(node.right.type, 'Identifier');
|
||||
assert.strictEqual(node.right.name, 'async');
|
||||
assert.deepEqual(node.right.loc, {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 6
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 11
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
describe('linefeed after async (simple)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'foo = async \t\t ',
|
||||
', function() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierAssignmentExpressionRHS(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionExpression as async', () => {
|
||||
node = find('FunctionExpression', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (single line comment)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'foo = async // flag enables async completion',
|
||||
', function() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierAssignmentExpressionRHS(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionExpression as async', () => {
|
||||
node = find('FunctionExpression', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (multiline comment), function', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'foo = async /* flag enables async completion',
|
||||
' of the callback */, function() {',
|
||||
'}'
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assertFindsIdentifierAssignmentExpressionRHS(ast);
|
||||
});
|
||||
|
||||
it('does not mark FunctionExpression as async', () => {
|
||||
node = find('FunctionExpression', ast);
|
||||
assert(!node.async, 'Expected node.async to be false');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe ('enhanced object literal', () => {
|
||||
var node, code;
|
||||
|
||||
describe('-', () => {
|
||||
beforeEach(() => {
|
||||
code = [
|
||||
'var x = {',
|
||||
' async foo() {}',
|
||||
'};'
|
||||
];
|
||||
node = find(
|
||||
// TODO: Is it really supposed to mark the Property async? Why not the FunctionExpression?
|
||||
'Property',
|
||||
parse(code)
|
||||
);
|
||||
});
|
||||
|
||||
it('marks the node value as async', () =>
|
||||
assert(node.value.async)
|
||||
);
|
||||
|
||||
it('does not mark the node as async', () =>
|
||||
assert(!node.async)
|
||||
);
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 12)
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, code[0].length + code[1].length + 1) // + 1 is due to newline char
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 2,
|
||||
column: 2
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 2,
|
||||
column: 16
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('linefeed after async (simple)', () => {
|
||||
it('fails to parse', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = {',
|
||||
' async \t\t ',
|
||||
' foo() {}',
|
||||
'};'
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (single line comment)', () => {
|
||||
it('fails to parse', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = {',
|
||||
' async // flag enables async completion',
|
||||
' foo() {}',
|
||||
'};'
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (multiline comment) illegal decl', () => {
|
||||
it('finds Identifier ExpressionStatement', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = {',
|
||||
' async /* flag enables async completion',
|
||||
' of the callback */ foo() {}',
|
||||
'};'
|
||||
]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe ('ArrowFunctionExpression', () => {
|
||||
var node, code;
|
||||
|
||||
describe('-', () => {
|
||||
beforeEach(() => {
|
||||
code = 'var x = async () => {}';
|
||||
node = find(
|
||||
'ArrowFunctionExpression',
|
||||
parse(code)
|
||||
);
|
||||
});
|
||||
|
||||
it('marks the node as async', () =>
|
||||
assert(node.async)
|
||||
);
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 8)
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, code.length)
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 1,
|
||||
column: 8
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 1,
|
||||
column: code.length
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('linefeed after async (simple)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'var x = async \t\t ',
|
||||
'()'
|
||||
]);
|
||||
});
|
||||
|
||||
it('fails to parse if linefeed preceeds arrow arguments', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = async \t\t ',
|
||||
'() => {}'
|
||||
]));
|
||||
});
|
||||
|
||||
it('finds CallExpression with "async" Identifier callee', () => {
|
||||
node = find('CallExpression', ast);
|
||||
assert.strictEqual(node.callee.type, 'Identifier');
|
||||
assert.strictEqual(node.callee.name, 'async');
|
||||
assert.deepEqual(node.callee.loc, {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 8
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 13
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (single line comment)', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'var x = async // flag enables async completion',
|
||||
'()'
|
||||
]);
|
||||
});
|
||||
|
||||
it('fails to parse if linefeed preceeds arrow arguments', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = async \t\t ',
|
||||
'() => {}'
|
||||
]));
|
||||
});
|
||||
|
||||
it('finds CallExpression with "async" Identifier callee', () => {
|
||||
node = find('CallExpression', ast);
|
||||
assert.strictEqual(node.callee.type, 'Identifier');
|
||||
assert.strictEqual(node.callee.name, 'async');
|
||||
assert.deepEqual(node.callee.loc, {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 8
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 13
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('linefeed after async (multiline comment) arrow decl', () => {
|
||||
var ast;
|
||||
beforeEach(() => {
|
||||
ast = parse([
|
||||
'var x = async /* flag enables async completion',
|
||||
' of the callback */()'
|
||||
]);
|
||||
});
|
||||
|
||||
it('fails to parse if linefeed preceeds arrow arguments', () => {
|
||||
assert.throws(() => parse([
|
||||
'var x = async /* flag enables async completion',
|
||||
' of the callback */() => {}'
|
||||
]));
|
||||
});
|
||||
|
||||
it('finds CallExpression with "async" Identifier callee', () => {
|
||||
node = find('CallExpression', ast);
|
||||
assert.strictEqual(node.callee.type, 'Identifier');
|
||||
assert.strictEqual(node.callee.name, 'async');
|
||||
assert.deepEqual(node.callee.loc, {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 8
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 13
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('await', () => {
|
||||
describe('-', () => {
|
||||
var node;
|
||||
|
||||
beforeEach(() => {
|
||||
node = find(
|
||||
'AwaitExpression',
|
||||
parse([
|
||||
'async function foo() {',
|
||||
' x = await bar()',
|
||||
'}'
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 29)
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, 40)
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 2,
|
||||
column: 6
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 2,
|
||||
column: 17
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
describe('outside a function (awaitAnywhere)', () => {
|
||||
var node;
|
||||
|
||||
beforeEach(() => {
|
||||
node = find(
|
||||
'AwaitExpression',
|
||||
parse(
|
||||
'x = await bar()',
|
||||
{awaitAnywhere:true}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('finds correct start position', () =>
|
||||
assert.strictEqual(node.start, 4)
|
||||
);
|
||||
|
||||
it('finds correct start line/column', () =>
|
||||
assert.deepEqual(node.loc.start, {
|
||||
line: 1,
|
||||
column: 4
|
||||
})
|
||||
);
|
||||
|
||||
it('finds correct end position', () =>
|
||||
assert.strictEqual(node.end, 15)
|
||||
);
|
||||
|
||||
it('finds correct end line/column', () =>
|
||||
assert.deepEqual(node.loc.end, {
|
||||
line: 1,
|
||||
column: 15
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
15
website/functions/node_modules/acorn-es7-plugin/test/xxx.js
generated
vendored
Normal file
15
website/functions/node_modules/acorn-es7-plugin/test/xxx.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
const acorn = require('acorn'); // 3.x
|
||||
require('..')(acorn);
|
||||
var code = "(async function x(){ console.log('hello'); }());";
|
||||
var ast = acorn.parse(code,{
|
||||
// Specify use of the plugin
|
||||
plugins:{asyncawait:true},
|
||||
// Specify the ecmaVersion
|
||||
ecmaVersion: 7
|
||||
}) ;
|
||||
// Show the AST
|
||||
console.log(JSON.stringify(ast,null,2)) ;
|
||||
}());
|
||||
|
Reference in New Issue
Block a user