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.

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-18 11:28:58 +08:00
import {
parseAction,
parseBinding,
parseInterpolationExpression,
parseTemplateBindings,
} from "angular-estree-parser";
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) {
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",
node,
comments,
2023-02-18 11:28:58 +08:00
};
},
locStart,
locEnd,
2018-11-04 23:03:07 +08:00
};
}
2023-03-24 08:44:25 +08:00
export const __ng_action = createParser(parseAction);
export const __ng_binding = createParser(parseBinding);
export const __ng_interpolation = createParser(parseInterpolationExpression);
export const __ng_directive = createParser(parseTemplateBindings);