@herb-tools/rewriter 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +49 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +49 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/loader.cjs +49 -9
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.esm.js +49 -9
- package/dist/loader.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/built-ins/action-view-tag-helper-to-html.ts +1 -1
- package/src/built-ins/html-to-action-view-tag-helper.ts +51 -5
package/dist/index.cjs
CHANGED
|
@@ -202,7 +202,7 @@ class Token {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
205
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
205
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/errors.ts.erb
|
|
206
206
|
class HerbError {
|
|
207
207
|
type;
|
|
208
208
|
message;
|
|
@@ -20096,7 +20096,7 @@ function deserializePrismNode(bytes, source) {
|
|
|
20096
20096
|
}
|
|
20097
20097
|
|
|
20098
20098
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
20099
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
20099
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/nodes.ts.erb
|
|
20100
20100
|
class Node {
|
|
20101
20101
|
type;
|
|
20102
20102
|
location;
|
|
@@ -23186,7 +23186,7 @@ class ParseResult extends Result {
|
|
|
23186
23186
|
}
|
|
23187
23187
|
|
|
23188
23188
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23189
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23189
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
23190
23190
|
/**
|
|
23191
23191
|
* Type guard functions for AST nodes.
|
|
23192
23192
|
* These functions provide type checking by combining both instanceof
|
|
@@ -23735,7 +23735,7 @@ function createSyntheticToken(value, type = "TOKEN_SYNTHETIC") {
|
|
|
23735
23735
|
}
|
|
23736
23736
|
|
|
23737
23737
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23738
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23738
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/visitor.ts.erb
|
|
23739
23739
|
class Visitor {
|
|
23740
23740
|
visit(node) {
|
|
23741
23741
|
if (!node)
|
|
@@ -24079,7 +24079,7 @@ class ActionViewTagHelperToHTMLRewriter extends ASTRewriter {
|
|
|
24079
24079
|
return "action-view-tag-helper-to-html";
|
|
24080
24080
|
}
|
|
24081
24081
|
get description() {
|
|
24082
|
-
return "Converts ActionView tag helpers
|
|
24082
|
+
return "Converts ActionView tag helpers to raw HTML elements";
|
|
24083
24083
|
}
|
|
24084
24084
|
rewrite(node, _context) {
|
|
24085
24085
|
const visitor = new ActionViewTagHelperToHTMLVisitor();
|
|
@@ -24112,6 +24112,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24112
24112
|
const prefixed = new Map();
|
|
24113
24113
|
let href = null;
|
|
24114
24114
|
let id = null;
|
|
24115
|
+
let src = null;
|
|
24115
24116
|
for (const child of children) {
|
|
24116
24117
|
if (!isHTMLAttributeNode(child))
|
|
24117
24118
|
continue;
|
|
@@ -24127,6 +24128,10 @@ function serializeAttributes(children, options = {}) {
|
|
|
24127
24128
|
id = value;
|
|
24128
24129
|
continue;
|
|
24129
24130
|
}
|
|
24131
|
+
if (options.extractSrc && name === "src") {
|
|
24132
|
+
src = value;
|
|
24133
|
+
continue;
|
|
24134
|
+
}
|
|
24130
24135
|
const dataMatch = name.match(/^(data|aria)-(.+)$/);
|
|
24131
24136
|
if (dataMatch) {
|
|
24132
24137
|
const [, prefix, rest] = dataMatch;
|
|
@@ -24143,7 +24148,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24143
24148
|
for (const [prefix, entries] of prefixed) {
|
|
24144
24149
|
parts.push(`${prefix}: { ${entries.join(", ")} }`);
|
|
24145
24150
|
}
|
|
24146
|
-
return { attributes: parts.join(", "), href, id };
|
|
24151
|
+
return { attributes: parts.join(", "), href, id, src };
|
|
24147
24152
|
}
|
|
24148
24153
|
function isTextOnlyBody(body) {
|
|
24149
24154
|
if (body.length !== 1 || !isHTMLTextNode(body[0]))
|
|
@@ -24169,8 +24174,10 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24169
24174
|
}
|
|
24170
24175
|
const isAnchor = tagName.value === "a";
|
|
24171
24176
|
const isTurboFrame = tagName.value === "turbo-frame";
|
|
24177
|
+
const isScript = tagName.value === "script";
|
|
24172
24178
|
const attributes = openTag.children.filter(child => !isWhitespaceNode(child));
|
|
24173
|
-
const
|
|
24179
|
+
const hasSrcAttribute = isScript && attributes.some(child => isHTMLAttributeNode(child) && getStaticAttributeName(child.name) === "src");
|
|
24180
|
+
const { attributes: attributesString, href, id, src } = serializeAttributes(attributes, { extractHref: isAnchor, extractId: isTurboFrame, extractSrc: isScript });
|
|
24174
24181
|
const hasBody = node.body && node.body.length > 0 && !node.is_void;
|
|
24175
24182
|
const isInlineContent = hasBody && isTextOnlyBody(node.body);
|
|
24176
24183
|
let content;
|
|
@@ -24183,6 +24190,14 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24183
24190
|
content = this.buildTurboFrameTagContent(node, attributesString, id, isInlineContent);
|
|
24184
24191
|
elementSource = "Turbo::FramesHelper#turbo_frame_tag";
|
|
24185
24192
|
}
|
|
24193
|
+
else if (isScript && hasSrcAttribute) {
|
|
24194
|
+
content = this.buildJavascriptIncludeTagContent(attributesString, src);
|
|
24195
|
+
elementSource = "ActionView::Helpers::AssetTagHelper#javascript_include_tag";
|
|
24196
|
+
}
|
|
24197
|
+
else if (isScript) {
|
|
24198
|
+
content = this.buildJavascriptTagContent(node, attributesString, isInlineContent);
|
|
24199
|
+
elementSource = "ActionView::Helpers::JavaScriptHelper#javascript_tag";
|
|
24200
|
+
}
|
|
24186
24201
|
else {
|
|
24187
24202
|
content = this.buildTagContent(tagName.value, node, attributesString, isInlineContent);
|
|
24188
24203
|
elementSource = "ActionView::Helpers::TagHelper#tag";
|
|
@@ -24199,7 +24214,8 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24199
24214
|
});
|
|
24200
24215
|
asMutable(node).open_tag = erbOpenTag;
|
|
24201
24216
|
asMutable(node).element_source = elementSource;
|
|
24202
|
-
const
|
|
24217
|
+
const isInlineLiteralContent = isScript && hasBody && node.body.length === 1 && isLiteralNode(node.body[0]) && !node.body[0].content.includes("\n");
|
|
24218
|
+
const isInlineForm = isInlineContent || isInlineLiteralContent || (isTurboFrame && !hasBody) || (isScript && hasSrcAttribute);
|
|
24203
24219
|
if (node.is_void) {
|
|
24204
24220
|
asMutable(node).close_tag = null;
|
|
24205
24221
|
}
|
|
@@ -24259,6 +24275,30 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24259
24275
|
}
|
|
24260
24276
|
return argString ? ` turbo_frame_tag ${argString} do ` : ` turbo_frame_tag do `;
|
|
24261
24277
|
}
|
|
24278
|
+
buildJavascriptTagContent(node, attributes, isInlineContent) {
|
|
24279
|
+
const bodyNode = node.body?.[0];
|
|
24280
|
+
const isInlineLiteral = bodyNode && isLiteralNode(bodyNode) && !bodyNode.content.includes("\n");
|
|
24281
|
+
const isInlineText = isInlineContent && isHTMLTextNode(bodyNode);
|
|
24282
|
+
if (isInlineText || isInlineLiteral) {
|
|
24283
|
+
const textContent = isHTMLTextNode(bodyNode) ? bodyNode.content : bodyNode.content;
|
|
24284
|
+
const args = [`"${textContent}"`];
|
|
24285
|
+
if (attributes)
|
|
24286
|
+
args.push(attributes);
|
|
24287
|
+
return ` javascript_tag ${args.join(", ")} `;
|
|
24288
|
+
}
|
|
24289
|
+
return attributes
|
|
24290
|
+
? ` javascript_tag ${attributes} do `
|
|
24291
|
+
: ` javascript_tag do `;
|
|
24292
|
+
}
|
|
24293
|
+
buildJavascriptIncludeTagContent(attributes, source) {
|
|
24294
|
+
const args = [];
|
|
24295
|
+
if (source)
|
|
24296
|
+
args.push(source);
|
|
24297
|
+
if (attributes)
|
|
24298
|
+
args.push(attributes);
|
|
24299
|
+
const argString = args.join(", ");
|
|
24300
|
+
return argString ? ` javascript_include_tag ${argString} ` : ` javascript_include_tag `;
|
|
24301
|
+
}
|
|
24262
24302
|
buildLinkToContent(node, attribute, href, isInlineContent) {
|
|
24263
24303
|
const args = [];
|
|
24264
24304
|
if (isInlineContent && isHTMLTextNode(node.body[0])) {
|
|
@@ -24282,7 +24322,7 @@ class HTMLToActionViewTagHelperRewriter extends ASTRewriter {
|
|
|
24282
24322
|
return "html-to-action-view-tag-helper";
|
|
24283
24323
|
}
|
|
24284
24324
|
get description() {
|
|
24285
|
-
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag)";
|
|
24325
|
+
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag, javascript_tag, javascript_include_tag)";
|
|
24286
24326
|
}
|
|
24287
24327
|
rewrite(node, _context) {
|
|
24288
24328
|
const visitor = new HTMLToActionViewTagHelperVisitor();
|