@wuchale/astro 0.2.5 → 0.2.6
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/transformer.d.ts +1 -1
- package/dist/transformer.js +10 -8
- package/package.json +1 -1
package/dist/transformer.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class AstroTransformer extends Transformer {
|
|
|
17
17
|
}>;
|
|
18
18
|
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf, matchUrl: UrlMatcher);
|
|
19
19
|
_byteOffsetToIndex: (offset?: number) => number;
|
|
20
|
-
|
|
20
|
+
_saveCorrectedRanges: (nodes: Node[], containerEnd: number) => void;
|
|
21
21
|
getRange: (node: Node | AttributeNode) => {
|
|
22
22
|
start: number;
|
|
23
23
|
end: number;
|
package/dist/transformer.js
CHANGED
|
@@ -9,8 +9,8 @@ export function parseExpr(content) {
|
|
|
9
9
|
const [opts, comments] = scriptParseOptionsWithComments();
|
|
10
10
|
return [ExprParser.parseExpressionAt(content, 0, opts), comments];
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
const nodesWithChildren = [
|
|
12
|
+
const tagNodes = ['element', 'component', 'custom-element'];
|
|
13
|
+
const nodesWithChildren = [...tagNodes, 'fragment'];
|
|
14
14
|
const rtRenderFunc = '_w_Tx_';
|
|
15
15
|
const u8decoder = new TextDecoder();
|
|
16
16
|
export class AstroTransformer extends Transformer {
|
|
@@ -36,11 +36,11 @@ export class AstroTransformer extends Transformer {
|
|
|
36
36
|
}
|
|
37
37
|
return u8decoder.decode(this.byteArray.slice(0, offset)).length;
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
_saveCorrectedRanges = (nodes, containerEnd) => {
|
|
40
40
|
for (const [i, child] of nodes.entries()) {
|
|
41
41
|
const isExpr = child.type === 'expression';
|
|
42
|
-
const
|
|
43
|
-
if (!(isExpr ||
|
|
42
|
+
const isTag = tagNodes.includes(child.type);
|
|
43
|
+
if (!(isExpr || isTag)) {
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
let start = this._byteOffsetToIndex(child.position?.start?.offset);
|
|
@@ -142,7 +142,7 @@ export class AstroTransformer extends Transformer {
|
|
|
142
142
|
let expr = '';
|
|
143
143
|
const msgs = [];
|
|
144
144
|
const { start, end } = this.getRange(node);
|
|
145
|
-
this.
|
|
145
|
+
this._saveCorrectedRanges(node.children, end);
|
|
146
146
|
for (const part of node.children) {
|
|
147
147
|
if (part.type === 'text') {
|
|
148
148
|
expr += part.value;
|
|
@@ -150,6 +150,8 @@ export class AstroTransformer extends Transformer {
|
|
|
150
150
|
}
|
|
151
151
|
msgs.push(...this.visitAs(part));
|
|
152
152
|
const { start, end } = this.getRange(part);
|
|
153
|
+
if (end == -1)
|
|
154
|
+
console.log(part, node);
|
|
153
155
|
expr += `"${' '.repeat(end - start)}"`;
|
|
154
156
|
}
|
|
155
157
|
msgs.push(...this._parseAndVisitExpr(expr, start + 1));
|
|
@@ -172,7 +174,7 @@ export class AstroTransformer extends Transformer {
|
|
|
172
174
|
msgs.push(...this.visitAs(attrib));
|
|
173
175
|
}
|
|
174
176
|
const { end } = this.getRange(node);
|
|
175
|
-
this.
|
|
177
|
+
this._saveCorrectedRanges(node.children, end);
|
|
176
178
|
msgs.push(...this._visitChildren(node.children));
|
|
177
179
|
this.currentElement = currentElement;
|
|
178
180
|
return msgs;
|
|
@@ -231,7 +233,7 @@ export class AstroTransformer extends Transformer {
|
|
|
231
233
|
return this._parseAndVisitExpr(node.value, this.frontMatterStart, true);
|
|
232
234
|
};
|
|
233
235
|
visitroot = (node) => {
|
|
234
|
-
this.
|
|
236
|
+
this._saveCorrectedRanges(node.children, this.content.length);
|
|
235
237
|
return this._visitChildren(node.children ?? []); // can be undefined!
|
|
236
238
|
};
|
|
237
239
|
visitAs = (node) => this.visit(node);
|