@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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core compiler infrastructure for TSRX syntax",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.16",
6
+ "version": "0.0.17",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
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
- const raw = this.input.slice(this.start, this.end);
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 = 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;
package/types/index.d.ts CHANGED
@@ -398,6 +398,7 @@ declare module 'estree' {
398
398
  export interface TextNode extends AST.BaseExpression {
399
399
  type: 'Text';
400
400
  expression: AST.Expression;
401
+ raw?: string;
401
402
  loc?: AST.SourceLocation;
402
403
  }
403
404