Files
test-repo/src/language-js/parse/angular.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
883 B
JavaScript
Raw Normal View History

2018-11-04 23:03:07 +08:00
"use strict";
2021-07-21 09:10:34 +08:00
const { locStart, locEnd } = require("../loc.js");
2018-11-04 23:03:07 +08:00
function createParser(_parse) {
const parse = (text, parsers, options) => {
const ngEstreeParser = require("angular-estree-parser");
const node = _parse(text, ngEstreeParser);
return {
type: "NGRoot",
node:
options.parser === "__ng_action" && node.type !== "NGChainedExpression"
? { ...node, type: "NGChainedExpression", expressions: [node] }
2018-11-04 23:03:07 +08:00
: node,
};
};
2020-07-14 21:52:38 +08:00
return { astFormat: "estree", parse, locStart, locEnd };
2018-11-04 23:03:07 +08:00
}
module.exports = {
parsers: {
__ng_action: createParser((text, ng) => ng.parseAction(text)),
__ng_binding: createParser((text, ng) => ng.parseBinding(text)),
__ng_interpolation: createParser((text, ng) => ng.parseInterpolation(text)),
__ng_directive: createParser((text, ng) => ng.parseTemplateBindings(text)),
},
};