2023-02-18 11:28:58 +08:00
|
|
|
import {
|
|
|
|
|
parseAction,
|
|
|
|
|
parseBinding,
|
|
|
|
|
parseInterpolationExpression,
|
|
|
|
|
parseTemplateBindings,
|
|
|
|
|
} from "angular-estree-parser";
|
2023-12-17 19:34:12 +00:00
|
|
|
import { locEnd, locStart } 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) {
|
2025-09-23 17:42:16 +08:00
|
|
|
let node = parseMethod(text);
|
|
|
|
|
// @ts-expect-error -- safe
|
|
|
|
|
const { comments } = node;
|
|
|
|
|
// @ts-expect-error -- safe
|
|
|
|
|
delete node.comments;
|
|
|
|
|
|
|
|
|
|
if (parseMethod === parseAction && node.type !== "NGChainedExpression") {
|
|
|
|
|
// @ts-expect-error -- expected
|
|
|
|
|
node = { ...node, type: "NGChainedExpression", expressions: [node] };
|
|
|
|
|
}
|
2023-01-22 20:32:34 +08:00
|
|
|
|
2023-02-18 11:28:58 +08:00
|
|
|
return {
|
|
|
|
|
type: "NGRoot",
|
2025-09-23 17:42:16 +08:00
|
|
|
node,
|
|
|
|
|
comments,
|
2023-02-18 11:28:58 +08:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
locStart,
|
|
|
|
|
locEnd,
|
2018-11-04 23:03:07 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 23:22:28 +08:00
|
|
|
export const __ng_action = /* @__PURE__ */ createParser(parseAction);
|
|
|
|
|
export const __ng_binding = /* @__PURE__ */ createParser(parseBinding);
|
|
|
|
|
export const __ng_interpolation = /* @__PURE__ */ createParser(
|
|
|
|
|
parseInterpolationExpression,
|
|
|
|
|
);
|
|
|
|
|
export const __ng_directive = /* @__PURE__ */ createParser(
|
|
|
|
|
parseTemplateBindings,
|
|
|
|
|
);
|