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-16 09:52:27 +08:00
|
|
|
const parse = async (text, options) => {
|
2022-08-10 19:32:44 +08:00
|
|
|
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"
|
2020-01-19 06:55:37 +08:00
|
|
|
? { ...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;
|