本文整理匯總了TypeScript中esprima.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了parse函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should discover dependencies from a syntax tree', () => {
const validIds = ['RESULT', 'GROSS', 'NET', 'STEP_1'];
const expression = `RESULT = (STEP_1 + GROSS - NET) / NET * STEP_1`;
const deps = discoverDependencies(esprima.parse(expression), validIds);
expect(deps.sort()).to.be.deep.equal(['RESULT', 'STEP_1', 'GROSS', 'NET'].sort());
});
示例2: purecheck
function purecheck(code: string,
{ globals = OPT_GLOBALS } = {}): FPErrorReport {
let tree = esprima.parse(code, {
loc: true,
comment: true,
sourceType: 'module',
});
return checkTree(tree, globals);
}
示例3: parse
export function parse(code: string): any {
if (code === undefined) {
throw new Error('Code parameter cannot be undefined');
}
if (code === '') {
return {};
}
var abstractSyntaxTree = esprima.parse(code, esprimaOptions);
return abstractSyntaxTree;
};
示例4: discoverDependencies
export function discoverDependencies(expression: string | ESTree.Program, validIdentifiers: string[]): string[] {
const ast = typeof expression === 'string' ? esprima.parse(expression) : expression;
const identifiers = [];
walk(ast, node => {
if (node &&
node.type === 'Identifier' &&
validIdentifiers.indexOf(node.name) !== -1 &&
identifiers.indexOf(node.name) === -1) {
identifiers.push(node.name);
}
});
return identifiers;
}
示例5: requires
function requires(code: string): string[] {
let ast = esprima.parse(code);
let requires: string[] = [];
estraverse.traverse(ast, {
enter: node => {
if (node.type == "CallExpression" && node.callee.name == "require") {
if (node.arguments > 1) {
throw "require 的參數大於 1";
}
if (node.arguments[0].type != "Literal") {
throw "require 的參數解析失敗";
}
requires.push(node.arguments[0].value);
}
}
});
return requires;
}
示例6: getNodeStructure
/**
* JSCrush version of following code
*
* (function () {
* var _console = []["filter"]["constructor"]("return this")().console;
* var _function = function () {};
*
* _console.log = _function;
* _console.info = _function;
* _console.warn = _function;
* _console.error = _function;
* _console
* })();
*
* @returns {INode}
*/
protected getNodeStructure (): INode {
return NodeUtils.getBlockStatementNodeByIndex(
esprima.parse(`
(function () {
var _ = '(\u0004\u0006\u0003\u0005[]' + '["filter"]["\u0007tructor"]' + '("return this")()' + '.' + '\u0003;\u0006\u0002\u0005\u0004};' + '_\u0003.log\u0001.in' + 'fo\u0001.' + 'war' + 'n\u0001.er' + 'r' + 'or\u0001})();' + '\u0001\u0005_\u0002;' + '_\u0003\u0002function' + '\u0003\u0007ole\u0004\u0002 ()' + '{\u0005 = \u0006var ' + '_\u0007cons',
Y,
$;
for (Y in $ = "\u0007\u0006\u0005\u0004\u0003\u0002\u0001") {
var arr = _.split($[Y]);
_ = arr.join(arr.pop());
}
[]["filter"]["constructor"](_)();
})()
`)
);
}
示例7: esprimaParse
function esprimaParse(source: string, options: ParserOptions = {}) {
try {
return esprima.parse(
source,
Object.assign(
{
range: true,
comment: true,
attachComment: true,
loc: true,
source: true
},
options
)
);
} catch (e) {
throw new ParseError(e);
}
}
示例8: function
paths.forEach((p:string) => {
var src = fs.readFileSync(p).toString()
var ast = esprima.parse(src, {comment: true, attachComment: true})
var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")
estraverse.traverse(ast, {
enter: function (n:any) {
if (matcher(n)) {
var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")
var methodList = n.arguments[1].properties.map((x:any) => {
var context = {
classname: classname,
name: x.key.name,
commentStr: (x.leadingComments && x.leadingComments.map((x: any) => { return x.value }).join('\n')) || ""
} as ExtraClientMethod
context.commentStr = context.commentStr.replace(/\n\s+\*/g, "\n *");
var m = /@api\s+private/.exec(context.commentStr)
if (m) {
return null
}
if (0 == context.commentStr.length) {
context.commentStr = null;
}
return context
}).filter((x: ExtraClientMethod) => {
return null != x
})
console.log("Adding class: ", classname, " and methods: ", methodList)
methodsToAdd[classname] = methodList
}
}
})
})
示例9: function
paths.forEach(function(p: string) {
var src = fs.readFileSync(p).toString()
var ast = esprima.parse(src)
var matcher = jsstana.createMatcher("(call (lookup AWS.util.update) ? ?)")
estraverse.traverse(ast, {
enter: function(n: any) {
if (matcher(n)) {
var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")
var methodList = n.arguments[1].properties.map(function(x: any) { return x.key.name })
console.log("Adding class: ", classname, " and methods: ", methodList)
methodsToAdd[classname] = methodList
}
}
})
})
示例10: function
fs.readFile(fullPath, "utf8", function(err, code) {
if (err) {
throw err;
}
n.Program.assert(esprimaParse(code), true);
n.Program.assert(esprimaParse(code, {
loc: true
}), true);
done();
});