@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/loader.esm.js
CHANGED
|
@@ -204,7 +204,7 @@ class Token {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
207
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
207
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/errors.ts.erb
|
|
208
208
|
class HerbError {
|
|
209
209
|
type;
|
|
210
210
|
message;
|
|
@@ -20098,7 +20098,7 @@ function deserializePrismNode(bytes, source) {
|
|
|
20098
20098
|
}
|
|
20099
20099
|
|
|
20100
20100
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
20101
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
20101
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/nodes.ts.erb
|
|
20102
20102
|
class Node {
|
|
20103
20103
|
type;
|
|
20104
20104
|
location;
|
|
@@ -23188,7 +23188,7 @@ class ParseResult extends Result {
|
|
|
23188
23188
|
}
|
|
23189
23189
|
|
|
23190
23190
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23191
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23191
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
23192
23192
|
/**
|
|
23193
23193
|
* Type guard functions for AST nodes.
|
|
23194
23194
|
* These functions provide type checking by combining both instanceof
|
|
@@ -23842,7 +23842,7 @@ function createSyntheticToken(value, type = "TOKEN_SYNTHETIC") {
|
|
|
23842
23842
|
}
|
|
23843
23843
|
|
|
23844
23844
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
23845
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.
|
|
23845
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.2/templates/javascript/packages/core/src/visitor.ts.erb
|
|
23846
23846
|
class Visitor {
|
|
23847
23847
|
visit(node) {
|
|
23848
23848
|
if (!node)
|
|
@@ -24186,7 +24186,7 @@ class ActionViewTagHelperToHTMLRewriter extends ASTRewriter {
|
|
|
24186
24186
|
return "action-view-tag-helper-to-html";
|
|
24187
24187
|
}
|
|
24188
24188
|
get description() {
|
|
24189
|
-
return "Converts ActionView tag helpers
|
|
24189
|
+
return "Converts ActionView tag helpers to raw HTML elements";
|
|
24190
24190
|
}
|
|
24191
24191
|
rewrite(node, _context) {
|
|
24192
24192
|
const visitor = new ActionViewTagHelperToHTMLVisitor();
|
|
@@ -24219,6 +24219,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24219
24219
|
const prefixed = new Map();
|
|
24220
24220
|
let href = null;
|
|
24221
24221
|
let id = null;
|
|
24222
|
+
let src = null;
|
|
24222
24223
|
for (const child of children) {
|
|
24223
24224
|
if (!isHTMLAttributeNode(child))
|
|
24224
24225
|
continue;
|
|
@@ -24234,6 +24235,10 @@ function serializeAttributes(children, options = {}) {
|
|
|
24234
24235
|
id = value;
|
|
24235
24236
|
continue;
|
|
24236
24237
|
}
|
|
24238
|
+
if (options.extractSrc && name === "src") {
|
|
24239
|
+
src = value;
|
|
24240
|
+
continue;
|
|
24241
|
+
}
|
|
24237
24242
|
const dataMatch = name.match(/^(data|aria)-(.+)$/);
|
|
24238
24243
|
if (dataMatch) {
|
|
24239
24244
|
const [, prefix, rest] = dataMatch;
|
|
@@ -24250,7 +24255,7 @@ function serializeAttributes(children, options = {}) {
|
|
|
24250
24255
|
for (const [prefix, entries] of prefixed) {
|
|
24251
24256
|
parts.push(`${prefix}: { ${entries.join(", ")} }`);
|
|
24252
24257
|
}
|
|
24253
|
-
return { attributes: parts.join(", "), href, id };
|
|
24258
|
+
return { attributes: parts.join(", "), href, id, src };
|
|
24254
24259
|
}
|
|
24255
24260
|
function isTextOnlyBody(body) {
|
|
24256
24261
|
if (body.length !== 1 || !isHTMLTextNode(body[0]))
|
|
@@ -24276,8 +24281,10 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24276
24281
|
}
|
|
24277
24282
|
const isAnchor = tagName.value === "a";
|
|
24278
24283
|
const isTurboFrame = tagName.value === "turbo-frame";
|
|
24284
|
+
const isScript = tagName.value === "script";
|
|
24279
24285
|
const attributes = openTag.children.filter(child => !isWhitespaceNode(child));
|
|
24280
|
-
const
|
|
24286
|
+
const hasSrcAttribute = isScript && attributes.some(child => isHTMLAttributeNode(child) && getStaticAttributeName(child.name) === "src");
|
|
24287
|
+
const { attributes: attributesString, href, id, src } = serializeAttributes(attributes, { extractHref: isAnchor, extractId: isTurboFrame, extractSrc: isScript });
|
|
24281
24288
|
const hasBody = node.body && node.body.length > 0 && !node.is_void;
|
|
24282
24289
|
const isInlineContent = hasBody && isTextOnlyBody(node.body);
|
|
24283
24290
|
let content;
|
|
@@ -24290,6 +24297,14 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24290
24297
|
content = this.buildTurboFrameTagContent(node, attributesString, id, isInlineContent);
|
|
24291
24298
|
elementSource = "Turbo::FramesHelper#turbo_frame_tag";
|
|
24292
24299
|
}
|
|
24300
|
+
else if (isScript && hasSrcAttribute) {
|
|
24301
|
+
content = this.buildJavascriptIncludeTagContent(attributesString, src);
|
|
24302
|
+
elementSource = "ActionView::Helpers::AssetTagHelper#javascript_include_tag";
|
|
24303
|
+
}
|
|
24304
|
+
else if (isScript) {
|
|
24305
|
+
content = this.buildJavascriptTagContent(node, attributesString, isInlineContent);
|
|
24306
|
+
elementSource = "ActionView::Helpers::JavaScriptHelper#javascript_tag";
|
|
24307
|
+
}
|
|
24293
24308
|
else {
|
|
24294
24309
|
content = this.buildTagContent(tagName.value, node, attributesString, isInlineContent);
|
|
24295
24310
|
elementSource = "ActionView::Helpers::TagHelper#tag";
|
|
@@ -24306,7 +24321,8 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24306
24321
|
});
|
|
24307
24322
|
asMutable(node).open_tag = erbOpenTag;
|
|
24308
24323
|
asMutable(node).element_source = elementSource;
|
|
24309
|
-
const
|
|
24324
|
+
const isInlineLiteralContent = isScript && hasBody && node.body.length === 1 && isLiteralNode(node.body[0]) && !node.body[0].content.includes("\n");
|
|
24325
|
+
const isInlineForm = isInlineContent || isInlineLiteralContent || (isTurboFrame && !hasBody) || (isScript && hasSrcAttribute);
|
|
24310
24326
|
if (node.is_void) {
|
|
24311
24327
|
asMutable(node).close_tag = null;
|
|
24312
24328
|
}
|
|
@@ -24366,6 +24382,30 @@ class HTMLToActionViewTagHelperVisitor extends Visitor {
|
|
|
24366
24382
|
}
|
|
24367
24383
|
return argString ? ` turbo_frame_tag ${argString} do ` : ` turbo_frame_tag do `;
|
|
24368
24384
|
}
|
|
24385
|
+
buildJavascriptTagContent(node, attributes, isInlineContent) {
|
|
24386
|
+
const bodyNode = node.body?.[0];
|
|
24387
|
+
const isInlineLiteral = bodyNode && isLiteralNode(bodyNode) && !bodyNode.content.includes("\n");
|
|
24388
|
+
const isInlineText = isInlineContent && isHTMLTextNode(bodyNode);
|
|
24389
|
+
if (isInlineText || isInlineLiteral) {
|
|
24390
|
+
const textContent = isHTMLTextNode(bodyNode) ? bodyNode.content : bodyNode.content;
|
|
24391
|
+
const args = [`"${textContent}"`];
|
|
24392
|
+
if (attributes)
|
|
24393
|
+
args.push(attributes);
|
|
24394
|
+
return ` javascript_tag ${args.join(", ")} `;
|
|
24395
|
+
}
|
|
24396
|
+
return attributes
|
|
24397
|
+
? ` javascript_tag ${attributes} do `
|
|
24398
|
+
: ` javascript_tag do `;
|
|
24399
|
+
}
|
|
24400
|
+
buildJavascriptIncludeTagContent(attributes, source) {
|
|
24401
|
+
const args = [];
|
|
24402
|
+
if (source)
|
|
24403
|
+
args.push(source);
|
|
24404
|
+
if (attributes)
|
|
24405
|
+
args.push(attributes);
|
|
24406
|
+
const argString = args.join(", ");
|
|
24407
|
+
return argString ? ` javascript_include_tag ${argString} ` : ` javascript_include_tag `;
|
|
24408
|
+
}
|
|
24369
24409
|
buildLinkToContent(node, attribute, href, isInlineContent) {
|
|
24370
24410
|
const args = [];
|
|
24371
24411
|
if (isInlineContent && isHTMLTextNode(node.body[0])) {
|
|
@@ -24389,7 +24429,7 @@ class HTMLToActionViewTagHelperRewriter extends ASTRewriter {
|
|
|
24389
24429
|
return "html-to-action-view-tag-helper";
|
|
24390
24430
|
}
|
|
24391
24431
|
get description() {
|
|
24392
|
-
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag)";
|
|
24432
|
+
return "Converts raw HTML elements to ActionView tag helpers (tag.*, turbo_frame_tag, javascript_tag, javascript_include_tag)";
|
|
24393
24433
|
}
|
|
24394
24434
|
rewrite(node, _context) {
|
|
24395
24435
|
const visitor = new HTMLToActionViewTagHelperVisitor();
|