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
896 B
JavaScript
Raw Normal View History

2022-02-21 15:53:02 +08:00
import { locStart, locEnd } from "../loc.js";
2018-11-04 23:03:07 +08:00
function createParser(_parse) {
2022-08-10 19:32:44 +08:00
const parse = async (text, parsers, options) => {
const ngEstreeParser = await import("angular-estree-parser");
2018-11-04 23:03:07 +08:00
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
}
2022-02-21 15:53:02 +08:00
const parser = {
2018-11-04 23:03:07 +08:00
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)),
},
};
2022-02-21 15:53:02 +08:00
export default parser;