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.

36 lines
931 B
JavaScript
Raw Normal View History

2023-02-18 11:28:58 +08:00
import {
parseAction,
parseBinding,
parseInterpolationExpression,
parseTemplateBindings,
} from "angular-estree-parser";
2022-02-21 15:53:02 +08:00
import { locStart, locEnd } from "../loc.js";
2018-11-04 23:03:07 +08:00
2023-01-22 20:32:34 +08:00
/**
2023-02-18 11:28:58 +08:00
* @param {parseAction | parseBinding | parseInterpolationExpression | parseTemplateBindings} parseMethod
2023-01-22 20:32:34 +08:00
*/
function createParser(parseMethod) {
2023-02-18 11:28:58 +08:00
return {
astFormat: "estree",
parse(text) {
const node = parseMethod(text);
2023-01-22 20:32:34 +08:00
2023-02-18 11:28:58 +08:00
return {
type: "NGRoot",
node:
parseMethod === parseAction && node.type !== "NGChainedExpression"
? { ...node, type: "NGChainedExpression", expressions: [node] }
: node,
};
},
locStart,
locEnd,
2018-11-04 23:03:07 +08:00
};
}
2023-03-13 12:34:56 +08:00
export const parsers = {
__ng_action: createParser(parseAction),
__ng_binding: createParser(parseBinding),
__ng_interpolation: createParser(parseInterpolationExpression),
__ng_directive: createParser(parseTemplateBindings),
2018-11-04 23:03:07 +08:00
};