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