@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.esm.js
CHANGED
|
@@ -200,7 +200,7 @@ class Token {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
203
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
203
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/errors.ts.erb
|
|
204
204
|
class HerbError {
|
|
205
205
|
type;
|
|
206
206
|
message;
|
|
@@ -20094,7 +20094,7 @@ function deserializePrismNode(bytes, source) {
|
|
|
20094
20094
|
}
|
|
20095
20095
|
|
|
20096
20096
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
20097
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
20097
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/nodes.ts.erb
|
|
20098
20098
|
class Node {
|
|
20099
20099
|
type;
|
|
20100
20100
|
location;
|
|
@@ -23184,7 +23184,7 @@ class ParseResult extends Result {
|
|
|
23184
23184
|
}
|
|
23185
23185
|
|
|
23186
23186
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23187
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23187
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
23188
23188
|
/**
|
|
23189
23189
|
* Type guard functions for AST nodes.
|
|
23190
23190
|
* These functions provide type checking by combining both instanceof
|
|
@@ -23733,7 +23733,7 @@ function createSyntheticToken(value, type = "TOKEN_SYNTHETIC") {
|
|
|
23733
23733
|
}
|
|
23734
23734
|
|
|
23735
23735
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23736
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23736
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/visitor.ts.erb
|
|
23737
23737
|
class Visitor {
|
|
23738
23738
|
visit(node) {
|
|
23739
23739
|
if (!node)
|
|
@@ -24077,7 +24077,7 @@ class ActionViewTagHelperToHTMLRewriter extends ASTRewriter {
|
|
|
24077
24077
|
return "action-view-tag-helper-to-html";
|
|
24078
24078
|
}
|
|
24079
24079
|
get description() {
|
|
24080
|
-
return "Converts ActionView tag helpers
|
|
24080
|
+
return "Converts ActionView tag helpers to raw HTML elements";
|
|
24081
24081
|
}
|
|
24082
24082
|
rewrite(node, _context) {
|
|
24083
24083
|
const visitor = new ActionViewTagHelperToHTMLVisitor();
|
|
@@ -24110,6 +24110,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24110
24110
|
const prefixed = new Map();
|
|
24111
24111
|
let href = null;
|
|
24112
24112
|
let id = null;
|
|
24113
|
+
let src = null;
|
|
24113
24114
|
for (const child of children) {
|
|
24114
24115
|
if (!isHTMLAttributeNode(child))
|
|
24115
24116
|
continue;
|
|
@@ -24125,6 +24126,10 @@ function serializeAttributes(children, options = {}) {
|
|
|
24125
24126
|
id = value;
|
|
24126
24127
|
continue;
|
|
24127
24128
|
}
|
|
24129
|
+
if (options.extractSrc && name === "src") {
|
|
24130
|
+
src = value;
|
|
24131
|
+
continue;
|
|
24132
|
+
}
|
|
24128
24133
|
const dataMatch = name.match(/^(data|aria)-(.+)$/);
|
|
24129
24134
|
if (dataMatch) {
|
|
24130
24135
|
const [, prefix, rest] = dataMatch;
|
|
@@ -24141,7 +24146,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24141
24146
|
for (const [prefix, entries] of prefixed) {
|
|
24142
24147
|
parts.push(`${prefix}: { ${entries.join(", ")} }`);
|
|
24143
24148
|
}
|
|
24144
|
-
return { attributes: parts.join(", "), href, id };
|
|
24149
|
+
return { attributes: parts.join(", "), href, id, src };
|
|
24145
24150
|
}
|
|
24146
24151
|
function isTextOnlyBody(body) {
|
|
24147
24152
|
if (body.length !== 1 || !isHTMLTextNode(body[0]))
|
|
@@ -24167,8 +24172,10 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24167
24172
|
}
|
|
24168
24173
|
const isAnchor = tagName.value === "a";
|
|
24169
24174
|
const isTurboFrame = tagName.value === "turbo-frame";
|
|
24175
|
+
const isScript = tagName.value === "script";
|
|
24170
24176
|
const attributes = openTag.children.filter(child => !isWhitespaceNode(child));
|
|
24171
|
-
const
|
|
24177
|
+
const hasSrcAttribute = isScript && attributes.some(child => isHTMLAttributeNode(child) && getStaticAttributeName(child.name) === "src");
|
|
24178
|
+
const { attributes: attributesString, href, id, src } = serializeAttributes(attributes, { extractHref: isAnchor, extractId: isTurboFrame, extractSrc: isScript });
|
|
24172
24179
|
const hasBody = node.body && node.body.length > 0 && !node.is_void;
|
|
24173
24180
|
const isInlineContent = hasBody && isTextOnlyBody(node.body);
|
|
24174
24181
|
let content;
|
|
@@ -24181,6 +24188,14 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24181
24188
|
content = this.buildTurboFrameTagContent(node, attributesString, id, isInlineContent);
|
|
24182
24189
|
elementSource = "Turbo::FramesHelper#turbo_frame_tag";
|
|
24183
24190
|
}
|
|
24191
|
+
else if (isScript && hasSrcAttribute) {
|
|
24192
|
+
content = this.buildJavascriptIncludeTagContent(attributesString, src);
|
|
24193
|
+
elementSource = "ActionView::Helpers::AssetTagHelper#javascript_include_tag";
|
|
24194
|
+
}
|
|
24195
|
+
else if (isScript) {
|
|
24196
|
+
content = this.buildJavascriptTagContent(node, attributesString, isInlineContent);
|
|
24197
|
+
elementSource = "ActionView::Helpers::JavaScriptHelper#javascript_tag";
|
|
24198
|
+
}
|
|
24184
24199
|
else {
|
|
24185
24200
|
content = this.buildTagContent(tagName.value, node, attributesString, isInlineContent);
|
|
24186
24201
|
elementSource = "ActionView::Helpers::TagHelper#tag";
|
|
@@ -24197,7 +24212,8 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24197
24212
|
});
|
|
24198
24213
|
asMutable(node).open_tag = erbOpenTag;
|
|
24199
24214
|
asMutable(node).element_source = elementSource;
|
|
24200
|
-
const
|
|
24215
|
+
const isInlineLiteralContent = isScript && hasBody && node.body.length === 1 && isLiteralNode(node.body[0]) && !node.body[0].content.includes("\n");
|
|
24216
|
+
const isInlineForm = isInlineContent || isInlineLiteralContent || (isTurboFrame && !hasBody) || (isScript && hasSrcAttribute);
|
|
24201
24217
|
if (node.is_void) {
|
|
24202
24218
|
asMutable(node).close_tag = null;
|
|
24203
24219
|
}
|
|
@@ -24257,6 +24273,30 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24257
24273
|
}
|
|
24258
24274
|
return argString ? ` turbo_frame_tag ${argString} do ` : ` turbo_frame_tag do `;
|
|
24259
24275
|
}
|
|
24276
|
+
buildJavascriptTagContent(node, attributes, isInlineContent) {
|
|
24277
|
+
const bodyNode = node.body?.[0];
|
|
24278
|
+
const isInlineLiteral = bodyNode && isLiteralNode(bodyNode) && !bodyNode.content.includes("\n");
|
|
24279
|
+
const isInlineText = isInlineContent && isHTMLTextNode(bodyNode);
|
|
24280
|
+
if (isInlineText || isInlineLiteral) {
|
|
24281
|
+
const textContent = isHTMLTextNode(bodyNode) ? bodyNode.content : bodyNode.content;
|
|
24282
|
+
const args = [`"${textContent}"`];
|
|
24283
|
+
if (attributes)
|
|
24284
|
+
args.push(attributes);
|
|
24285
|
+
return ` javascript_tag ${args.join(", ")} `;
|
|
24286
|
+
}
|
|
24287
|
+
return attributes
|
|
24288
|
+
? ` javascript_tag ${attributes} do `
|
|
24289
|
+
: ` javascript_tag do `;
|
|
24290
|
+
}
|
|
24291
|
+
buildJavascriptIncludeTagContent(attributes, source) {
|
|
24292
|
+
const args = [];
|
|
24293
|
+
if (source)
|
|
24294
|
+
args.push(source);
|
|
24295
|
+
if (attributes)
|
|
24296
|
+
args.push(attributes);
|
|
24297
|
+
const argString = args.join(", ");
|
|
24298
|
+
return argString ? ` javascript_include_tag ${argString} ` : ` javascript_include_tag `;
|
|
24299
|
+
}
|
|
24260
24300
|
buildLinkToContent(node, attribute, href, isInlineContent) {
|
|
24261
24301
|
const args = [];
|
|
24262
24302
|
if (isInlineContent && isHTMLTextNode(node.body[0])) {
|
|
@@ -24280,7 +24320,7 @@ class HTMLToActionViewTagHelperRewriter extends ASTRewriter {
|
|
|
24280
24320
|
return "html-to-action-view-tag-helper";
|
|
24281
24321
|
}
|
|
24282
24322
|
get description() {
|
|
24283
|
-
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag)";
|
|
24323
|
+
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag, javascript_tag, javascript_include_tag)";
|
|
24284
24324
|
}
|
|
24285
24325
|
rewrite(node, _context) {
|
|
24286
24326
|
const visitor = new HTMLToActionViewTagHelperVisitor();
|