MCPcopy Create free account
hub / github.com/ampproject/amphtml / create

Function create

build-system/eslint-rules/html-template.js:16–184  ·  view source on GitHub ↗

* @param {*} context * @return {{ * CallExpression: {Function(node: CompilerNode): void} * TaggedTemplateExpression: {Function(node: CompilerNode): void} * }}

(context)

Source from the content-addressed store, hash-verified

14 * }}
15 */
16function create(context) {
17 /**
18 * @param {CompilerNode} node
19 */
20 function tagCannotBeCalled(node) {
21 const {name} = node.callee;
22 context.report({
23 node,
24 message:
25 `The ${name} helper MUST NOT be called directly. ` +
26 'Instead, use it as a template literal tag: ``` ' +
27 name +
28 '`<div />` ```',
29 });
30 }
31
32 /**
33 * @param {CompilerNode} node
34 */
35 function factoryUsage(node) {
36 const {parent} = node;
37 const {name} = node.callee;
38
39 const expectedTagName = staticTemplateFactories[name];
40
41 if (parent.type === 'TaggedTemplateExpression' && parent.tag === node) {
42 tagUsage(parent, `${name}()`);
43 return;
44 }
45
46 if (
47 parent.type === 'VariableDeclarator' &&
48 parent.init === node &&
49 parent.id.type === 'Identifier' &&
50 parent.id.name === expectedTagName
51 ) {
52 return;
53 }
54
55 if (
56 parent.type === 'AssignmentExpression' &&
57 parent.right === node &&
58 parent.left.type === 'Identifier' &&
59 parent.left.name === expectedTagName
60 ) {
61 return;
62 }
63
64 context.report({
65 node,
66 message:
67 `${name} result must be stored into a variable named ` +
68 `"${expectedTagName}", or used as the tag of a tagged template ` +
69 'literal.',
70 });
71 }
72
73 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected