@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/rewriter",
3
- "version": "0.9.4",
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.4",
42
- "@herb-tools/tailwind-class-sorter": "0.9.4",
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.4"
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
- const nodeType = prismNode.constructor.name
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
- const nodeType = prismNode.constructor.name
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 (nodeType === INTERPOLATED_STRING_NODE_TYPE) {
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
- const partType = part.constructor.name
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 (partType === EMBEDDED_STATEMENTS_NODE_TYPE) {
156
+ } else if (isPrismNodeType(part, EMBEDDED_STATEMENTS_NODE_TYPE)) {
163
157
  const expression = this.extractExpressionSource(part, source)
164
158
 
165
159
  if (expression) {