@herb-tools/rewriter 0.9.4 → 0.9.5
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 +212 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +212 -73
- package/dist/index.esm.js.map +1 -1
- package/dist/loader.cjs +212 -73
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.esm.js +212 -73
- package/dist/loader.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/built-ins/erb-string-to-direct-output.ts +6 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/rewriter",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Rewriter system for transforming HTML+ERB AST nodes and formatted strings",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://herb-tools.dev",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@herb-tools/core": "0.9.
|
|
42
|
-
"@herb-tools/tailwind-class-sorter": "0.9.
|
|
41
|
+
"@herb-tools/core": "0.9.5",
|
|
42
|
+
"@herb-tools/tailwind-class-sorter": "0.9.5",
|
|
43
43
|
"tinyglobby": "^0.2.15"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@herb-tools/printer": "0.9.
|
|
46
|
+
"@herb-tools/printer": "0.9.5"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"package.json",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Visitor, isERBOutputNode, createLiteral, createERBOutputNode, findParentArray } from "@herb-tools/core"
|
|
1
|
+
import { Visitor, isERBOutputNode, createLiteral, createERBOutputNode, findParentArray, isPrismNodeType } from "@herb-tools/core"
|
|
2
2
|
|
|
3
3
|
import { ASTRewriter } from "../ast-rewriter.js"
|
|
4
4
|
|
|
@@ -102,9 +102,7 @@ export class ERBStringToDirectOutputRewriter extends ASTRewriter {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
static isStringOutputNode(prismNode: PrismNode): boolean {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return nodeType === STRING_NODE_TYPE || nodeType === INTERPOLATED_STRING_NODE_TYPE
|
|
105
|
+
return isPrismNodeType(prismNode, STRING_NODE_TYPE) || isPrismNodeType(prismNode, INTERPOLATED_STRING_NODE_TYPE)
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
static extractStringContent(stringNode: PrismNode, source: string): string {
|
|
@@ -136,14 +134,12 @@ export class ERBStringToDirectOutputRewriter extends ASTRewriter {
|
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
static extractReplacementParts(prismNode: PrismNode, source: string): ReplacementPart[] | null {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (nodeType === STRING_NODE_TYPE) {
|
|
137
|
+
if (isPrismNodeType(prismNode, STRING_NODE_TYPE)) {
|
|
142
138
|
const textContent = this.extractStringContent(prismNode, source)
|
|
143
139
|
return [{ type: "text", content: textContent }]
|
|
144
140
|
}
|
|
145
141
|
|
|
146
|
-
if (
|
|
142
|
+
if (isPrismNodeType(prismNode, INTERPOLATED_STRING_NODE_TYPE)) {
|
|
147
143
|
const parts = prismNode.parts
|
|
148
144
|
|
|
149
145
|
if (!parts || parts.length === 0) return null
|
|
@@ -151,15 +147,13 @@ export class ERBStringToDirectOutputRewriter extends ASTRewriter {
|
|
|
151
147
|
const replacementParts: ReplacementPart[] = []
|
|
152
148
|
|
|
153
149
|
for (const part of parts) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (partType === STRING_NODE_TYPE) {
|
|
150
|
+
if (isPrismNodeType(part, STRING_NODE_TYPE)) {
|
|
157
151
|
const textContent = this.extractStringContent(part, source)
|
|
158
152
|
|
|
159
153
|
if (textContent) {
|
|
160
154
|
replacementParts.push({ type: "text", content: textContent })
|
|
161
155
|
}
|
|
162
|
-
} else if (
|
|
156
|
+
} else if (isPrismNodeType(part, EMBEDDED_STATEMENTS_NODE_TYPE)) {
|
|
163
157
|
const expression = this.extractExpressionSource(part, source)
|
|
164
158
|
|
|
165
159
|
if (expression) {
|