ember-estree 0.6.8 → 0.6.10

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": "ember-estree",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "ESTree generator for gjs and gts file used by ember",
5
5
  "keywords": [
6
6
  "AST",
package/src/parse.js CHANGED
@@ -361,10 +361,16 @@ function toPlaceholderJS(source, parseResults) {
361
361
 
362
362
  parts.push(source.slice(cursor, start));
363
363
 
364
+ // Blank out backticks and dollar signs instead of backslash-escaping
365
+ // them: escaping grows the content, and once the growth exceeds the
366
+ // padding slack the placeholder no longer lines up with the original
367
+ // region — matchPlaceholder then rejects it and the raw placeholder
368
+ // leaks into the AST (ember-tooling/ember-eslint-parser#230). The
369
+ // content is discarded when the Glimmer AST is spliced in, so only
370
+ // its length and line structure matter.
364
371
  const content = source
365
372
  .slice(pr.contentRange.startUtf16Codepoint, pr.contentRange.endUtf16Codepoint)
366
- .replace(/`/g, "\\`")
367
- .replace(/\$/g, "\\$");
373
+ .replace(/[`$]/g, " ");
368
374
 
369
375
  if (pr.type === "class-member") {
370
376
  const spaces = tplLength - content.length - 10; // "static{`" + "`}" = 10
package/src/print.js CHANGED
@@ -26,9 +26,15 @@ export function print(node) {
26
26
  case "Literal":
27
27
  case "StringLiteral":
28
28
  if (typeof node.value === "string") {
29
+ // Prefer the original source: it preserves escape sequences
30
+ // (`\n`, `\t`, `\uXXXX`, escaped quotes) and the original quote
31
+ // style exactly. Emitting the cooked `value` turns escapes into raw
32
+ // characters and corrupts the string (e.g. `'\n'` -> a real newline,
33
+ // which breaks a single-quoted literal).
29
34
  const raw = node.extra?.raw ?? node.raw;
30
- const quote = raw && (raw[0] === "'" || raw[0] === '"' || raw[0] === "`") ? raw[0] : '"';
31
- return `${quote}${node.value}${quote}`;
35
+ if (raw != null) return raw;
36
+ // Synthesized node with no source — quote and escape the value.
37
+ return JSON.stringify(node.value);
32
38
  }
33
39
  if (node.raw != null) return node.raw;
34
40
  return String(node.value);
@@ -83,6 +89,12 @@ export function print(node) {
83
89
  case "ChainExpression":
84
90
  return print(node.expression);
85
91
 
92
+ case "V8IntrinsicExpression": {
93
+ const name = typeof node.name === "string" ? node.name : print(node.name);
94
+ const args = (node.arguments ?? []).map(print).join(", ");
95
+ return `%${name}(${args})`;
96
+ }
97
+
86
98
  case "ParenthesizedExpression":
87
99
  return `(${print(node.expression)})`;
88
100
 
@@ -203,7 +215,7 @@ export function print(node) {
203
215
  case "BlockStatement":
204
216
  case "StaticBlock": {
205
217
  const body = (node.body ?? []).map(print).join("\n");
206
- return `{\n${body}\n}`;
218
+ return braceBlock(body);
207
219
  }
208
220
 
209
221
  case "EmptyStatement":
@@ -244,13 +256,13 @@ export function print(node) {
244
256
  case "SwitchStatement": {
245
257
  const disc = print(node.discriminant);
246
258
  const cases = (node.cases ?? []).map(print).join("\n");
247
- return `switch (${disc}) {\n${cases}\n}`;
259
+ return `switch (${disc}) ${braceBlock(cases)}`;
248
260
  }
249
261
 
250
262
  case "SwitchCase": {
251
263
  const test = node.test ? `case ${print(node.test)}:` : "default:";
252
264
  const body = (node.consequent ?? []).map(print).join("\n");
253
- return `${test}\n${body}`;
265
+ return body ? `${test}\n${indent(body)}` : test;
254
266
  }
255
267
 
256
268
  case "ThrowStatement":
@@ -324,7 +336,7 @@ export function print(node) {
324
336
 
325
337
  case "ClassBody": {
326
338
  const body = (node.body ?? []).map(print).join("\n");
327
- return `{\n${body}\n}`;
339
+ return braceBlock(body);
328
340
  }
329
341
 
330
342
  case "MethodDefinition":
@@ -544,6 +556,16 @@ export function print(node) {
544
556
  case "TSParenthesizedType":
545
557
  return `(${print(node.typeAnnotation)})`;
546
558
 
559
+ // JSDoc type syntax (`?Foo`, `!Foo`, `?`) — `postfix` flips prefix/suffix.
560
+ case "TSJSDocNullableType":
561
+ return node.postfix ? `${print(node.typeAnnotation)}?` : `?${print(node.typeAnnotation)}`;
562
+
563
+ case "TSJSDocNonNullableType":
564
+ return node.postfix ? `${print(node.typeAnnotation)}!` : `!${print(node.typeAnnotation)}`;
565
+
566
+ case "TSJSDocUnknownType":
567
+ return "?";
568
+
547
569
  case "TSTupleType": {
548
570
  const elems = (node.elementTypes ?? []).map(print).join(", ");
549
571
  return `[${elems}]`;
@@ -662,7 +684,7 @@ export function print(node) {
662
684
 
663
685
  case "TSInterfaceBody": {
664
686
  const body = (node.body ?? []).map(print).join("\n");
665
- return `{\n${body}\n}`;
687
+ return braceBlock(body);
666
688
  }
667
689
 
668
690
  case "TSInterfaceHeritage":
@@ -683,8 +705,15 @@ export function print(node) {
683
705
  const declare = node.declare ? "declare " : "";
684
706
  const constKw = node.const ? "const " : "";
685
707
  const id = print(node.id);
708
+ // Newer oxc nests members in a TSEnumBody child; older versions put
709
+ // `members` directly on the declaration.
710
+ const members = (node.body?.members ?? node.members ?? []).map(print).join(",\n");
711
+ return `${declare}${constKw}enum ${id} ${braceBlock(members)}`;
712
+ }
713
+
714
+ case "TSEnumBody": {
686
715
  const members = (node.members ?? []).map(print).join(",\n");
687
- return `${declare}${constKw}enum ${id} {\n${members}\n}`;
716
+ return braceBlock(members);
688
717
  }
689
718
 
690
719
  case "TSEnumMember": {
@@ -701,7 +730,7 @@ export function print(node) {
701
730
 
702
731
  case "TSModuleBlock": {
703
732
  const body = (node.body ?? []).map(print).join("\n");
704
- return `{\n${body}\n}`;
733
+ return braceBlock(body);
705
734
  }
706
735
 
707
736
  case "TSNamespaceExportDeclaration":
@@ -922,6 +951,30 @@ export function print(node) {
922
951
  * @param {object} node
923
952
  * @return {string}
924
953
  */
954
+ /**
955
+ * Indents every non-empty line of a block's inner content by one level.
956
+ * Nesting compounds naturally: each enclosing block re-indents the
957
+ * already-formatted child string.
958
+ * @param {string} text
959
+ * @return {string}
960
+ */
961
+ function indent(text) {
962
+ return text
963
+ .split("\n")
964
+ .map((line) => (line ? ` ${line}` : line))
965
+ .join("\n");
966
+ }
967
+
968
+ /**
969
+ * Wraps already-joined statement text in a brace block, indented one level.
970
+ * Empty content collapses to `{}`.
971
+ * @param {string} inner
972
+ * @return {string}
973
+ */
974
+ function braceBlock(inner) {
975
+ return inner ? `{\n${indent(inner)}\n}` : "{}";
976
+ }
977
+
925
978
  function printTypeAnnotated(name, node) {
926
979
  const optional = node.optional ? "?" : "";
927
980
  const typeAnnotation = node.typeAnnotation ? print(node.typeAnnotation) : "";