@tsrx/core 0.0.16 → 0.0.17
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 +1 -1
- package/src/plugin.js +79 -2
- package/types/index.d.ts +1 -0
package/package.json
CHANGED
package/src/plugin.js
CHANGED
|
@@ -196,6 +196,79 @@ export function TSRXPlugin(config) {
|
|
|
196
196
|
this.#filename = tsrx_options?.filename || null;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
#previousNonWhitespaceChar() {
|
|
200
|
+
let index = this.pos - 1;
|
|
201
|
+
while (index >= 0) {
|
|
202
|
+
const ch = this.input.charCodeAt(index);
|
|
203
|
+
if (ch !== 32 && ch !== 9 && ch !== 10 && ch !== 13) {
|
|
204
|
+
return ch;
|
|
205
|
+
}
|
|
206
|
+
index--;
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
#isDoubleQuotedTextChildStart() {
|
|
212
|
+
if (this.#path.findLast((n) => n.type === 'TsxCompat' || n.type === 'Tsx')) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const parent = this.#path.at(-1);
|
|
217
|
+
if (!parent || (parent.type !== 'Component' && parent.type !== 'Element')) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const context = this.curContext();
|
|
222
|
+
if (context === tstc.tc_oTag || context === tstc.tc_cTag) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const prev = this.#previousNonWhitespaceChar();
|
|
227
|
+
return (
|
|
228
|
+
prev === null ||
|
|
229
|
+
prev === 34 || // "
|
|
230
|
+
prev === 59 || // ;
|
|
231
|
+
prev === 62 || // >
|
|
232
|
+
prev === 123 || // {
|
|
233
|
+
prev === 125 // }
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#readDoubleQuotedTextChildToken() {
|
|
238
|
+
const start = this.pos;
|
|
239
|
+
let out = '';
|
|
240
|
+
this.pos++;
|
|
241
|
+
let chunkStart = this.pos;
|
|
242
|
+
|
|
243
|
+
while (this.pos < this.input.length) {
|
|
244
|
+
const ch = this.input.charCodeAt(this.pos);
|
|
245
|
+
|
|
246
|
+
if (ch === 34 /* " */) {
|
|
247
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
248
|
+
this.pos++;
|
|
249
|
+
return this.finishToken(tt.string, out);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (ch === 38 /* & */) {
|
|
253
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
254
|
+
out += this.jsx_readEntity();
|
|
255
|
+
chunkStart = this.pos;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (acorn.isNewLine(ch)) {
|
|
260
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
261
|
+
out += this.jsx_readNewLine(true);
|
|
262
|
+
chunkStart = this.pos;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
this.pos++;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this.raise(start, 'Unterminated double-quoted text child');
|
|
270
|
+
}
|
|
271
|
+
|
|
199
272
|
/**
|
|
200
273
|
* @param {number} position
|
|
201
274
|
* @param {number} end
|
|
@@ -559,6 +632,10 @@ export function TSRXPlugin(config) {
|
|
|
559
632
|
* @type {Parse.Parser['getTokenFromCode']}
|
|
560
633
|
*/
|
|
561
634
|
getTokenFromCode(code) {
|
|
635
|
+
if (code === 34 && this.#isDoubleQuotedTextChildStart()) {
|
|
636
|
+
return this.#readDoubleQuotedTextChildToken();
|
|
637
|
+
}
|
|
638
|
+
|
|
562
639
|
if (code !== 60) {
|
|
563
640
|
this.#allowTagStartAfterDoubleQuotedText = false;
|
|
564
641
|
}
|
|
@@ -1318,12 +1395,12 @@ export function TSRXPlugin(config) {
|
|
|
1318
1395
|
parseDoubleQuotedTextChild() {
|
|
1319
1396
|
const node = /** @type {AST.TextNode} */ (this.startNode());
|
|
1320
1397
|
const expression = /** @type {AST.Literal} */ (this.startNode());
|
|
1321
|
-
|
|
1398
|
+
node.raw = this.input.slice(this.start, this.end);
|
|
1322
1399
|
const end = this.end;
|
|
1323
1400
|
const endLoc = this.endLoc;
|
|
1324
1401
|
|
|
1325
1402
|
expression.value = this.value;
|
|
1326
|
-
expression.raw =
|
|
1403
|
+
expression.raw = JSON.stringify(this.value);
|
|
1327
1404
|
node.expression = this.finishNodeAt(expression, 'Literal', end, endLoc);
|
|
1328
1405
|
|
|
1329
1406
|
this.#allowTagStartAfterDoubleQuotedText = true;
|