From a7961252465297e10accdf6fc8eda0c3d9b459e7 Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 3 Nov 2023 14:55:37 +0100 Subject: [PATCH] update with custom parser from ember eslint plugin --- design.md | 11 +- examples/bin/test.mjs | 3 +- examples/package.json | 2 +- pnpm-lock.yaml | 225 +- src/config.ts | 3 - src/parse.ts | 420 +- src/print/index.ts | 141 +- src/print/template.ts | 19 +- src/types/glimmer.ts | 225 - src/types/prettier.ts | 8 - src/types/raw.ts | 133 - src/utils/ambiguity.ts | 103 - src/utils/index.ts | 24 - tests/helpers/ambiguous.ts | 4 +- tests/helpers/cases.ts | 4 +- tests/package.json | 3 +- .../__snapshots__/format.test.ts.snap | 8 +- .../arrow-parens-avoid.test.ts.snap | 24 +- .../__snapshots__/index.test.ts.snap | 3730 ++++++++++++----- .../__snapshots__/semi-false.test.ts.snap | 3694 +++++++++++----- .../__snapshots__/semi-false.test.ts.snap | 4 +- .../template-export-default.test.ts.snap | 8 +- tests/unit-tests/preprocessed.test.ts | 69 - vite.config.ts | 3 + 24 files changed, 5560 insertions(+), 3308 deletions(-) delete mode 100644 src/types/glimmer.ts delete mode 100644 src/types/prettier.ts delete mode 100644 src/types/raw.ts delete mode 100644 src/utils/ambiguity.ts delete mode 100644 tests/unit-tests/preprocessed.test.ts diff --git a/design.md b/design.md index 03f01f88..a964676b 100644 --- a/design.md +++ b/design.md @@ -1,10 +1,11 @@ # The Plan -1. Run `Preprocessor.process` from content-tag to convert gjs files with ` as TemplateOnlyComponent; oops => {}; " `; @@ -913,7 +913,7 @@ export interface Signature { as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -986,7 +986,7 @@ oops => {}; exports[`ambiguous > config > arrowParens: "avoid" > (oops) => {} > with semi, without newline > it formats ../cases/gjs/simple.gjs 1`] = ` " +; oops => {}; " `; @@ -1005,7 +1005,7 @@ export interface Signature { module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. - as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -1173,7 +1173,7 @@ export interface Signature { as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -1192,7 +1192,7 @@ export interface Signature { module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. - as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -1244,7 +1244,7 @@ export interface Signature { as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -1262,7 +1262,7 @@ export interface Signature { module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. - as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; @@ -1311,7 +1311,7 @@ export interface Signature { as TemplateOnlyComponent + as TemplateOnlyComponent; oops => {}; " `; diff --git a/tests/unit-tests/ambiguous/__snapshots__/index.test.ts.snap b/tests/unit-tests/ambiguous/__snapshots__/index.test.ts.snap index 6a1bc150..7af2c40c 100644 --- a/tests/unit-tests/ambiguous/__snapshots__/index.test.ts.snap +++ b/tests/unit-tests/ambiguous/__snapshots__/index.test.ts.snap @@ -6,7 +6,7 @@ exports[`ambiguous > config > default > (oh, no) => {} > with semi, with newline module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + (oh, no) => {}; " `; @@ -266,7 +266,7 @@ exports[`ambiguous > config > default > (oh, no) => {} > with semi, without newl module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + (oh, no) => {}; " `; @@ -664,7 +664,7 @@ exports[`ambiguous > config > default > (oops) => {} > with semi, with newline > module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + (oops) => {}; " `; @@ -924,7 +924,7 @@ exports[`ambiguous > config > default > (oops) => {} > with semi, without newlin module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + (oops) => {}; " `; @@ -1322,7 +1322,7 @@ exports[`ambiguous > config > default > +"oops" > with semi, with newline > it f module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + +\\"oops\\"; " `; @@ -1582,7 +1582,7 @@ exports[`ambiguous > config > default > +"oops" > with semi, without newline > i module top level component. Explicit default export module top level component. Explicit default export module top level component. Explicit default export module top level component. -; + +\\"oops\\"; " `; @@ -1836,67 +1836,44 @@ export interface Signature { " `; -exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/js-only.gjs 1`] = ` -"const num = 1 + \\"oops\\"; -" -`; - -exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/js-only.gts 1`] = ` -"const num: number = 1 + \\"oops\\"; -" -`; - -exports[`ambiguous > config > default > +"oops" > without semi, without newline > it formats ../cases/gjs/js-only.gjs 1`] = ` -"const num = 1 + \\"oops\\"; -" -`; - -exports[`ambiguous > config > default > +"oops" > without semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` -"const num: number = 1 + \\"oops\\"; -" -`; - -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/default-export.gjs 1`] = ` -" + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/exported-mod-var.gjs 1`] = ` -"export const Exported = ; -/oops/; +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/exported-mod-var.gjs 1`] = ` +"export const Exported = + + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/js-only.gjs 1`] = ` -"const num = 1; -/oops/; +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/js-only.gjs 1`] = ` +"const num = 1 + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/mod-var.gjs 1`] = ` -"const Private = ; -/oops/; +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/mod-var.gjs 1`] = ` +"const Private = + + \\"oops\\"; -const What = ; -/oops/; +const What = + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/multiple-declarations.gjs 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/multiple-declarations.gjs 1`] = ` "const ModVar1 = , ModVar2 = , - num = 1; -/oops/; + num = 1 + \\"oops\\"; const bool = false, ModVar3 = , - ModVar4 = ; -/oops/; + ModVar4 = + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gjs/simple.gjs 1`] = ` -"; -/oops/; +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gjs/simple.gjs 1`] = ` +" + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/default-export.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/default-export.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -1938,17 +1910,16 @@ export interface Signature { Yields: []; } - as TemplateOnlyComponent) + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -1957,16 +1928,16 @@ export interface Signature { Yields: []; } -export const Exported: TemplateOnlyComponent = ; -/oops/; +export const Exported: TemplateOnlyComponent = + + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -1975,22 +1946,21 @@ export interface Signature { Yields: []; } -export const Exported = as TemplateOnlyComponent; -/oops/; +export const Exported = + ( as TemplateOnlyComponent) + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/js-only.gts 1`] = ` -"const num: number = 1; -/oops/; +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/js-only.gts 1`] = ` +"const num: number = 1 + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/mod-var.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -1999,16 +1969,16 @@ export interface Signature { Yields: []; } -const Private: TemplateOnlyComponent = ; -/oops/; +const Private: TemplateOnlyComponent = + + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2017,16 +1987,16 @@ export interface Signature { Yields: []; } -const Private = as TemplateOnlyComponent; -/oops/; +const Private = + ( as TemplateOnlyComponent) + \\"oops\\"; " `; -exports[`ambiguous > config > default > /oops/ > with semi, with newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` +exports[`ambiguous > config > default > +"oops" > without semi, with newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2045,8 +2015,7 @@ const ModVar1: TemplateOnlyComponent = as TemplateOnlyComponent - + as TemplateOnlyComponent; +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2858,13 +2680,11 @@ export const Exported: TemplateOnlyComponent = ; - +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2878,21 +2698,17 @@ export const Exported = as TemplateOnlyComponent; - +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` "const num: number = 1; - +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/mod-var.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2906,13 +2722,11 @@ const Private: TemplateOnlyComponent = ; - +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2926,13 +2740,11 @@ const Private = as TemplateOnlyComponent; - +/oops/; " `; -exports[`ambiguous > config > default > > with semi, without newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` +exports[`ambiguous > config > default > /oops/ > with semi, without newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -2952,9 +2764,8 @@ const ModVar1: TemplateOnlyComponent = , num = 1; - +/oops/; + const bool: boolean = false, ModVar3: TemplateOnlyComponent = as TemplateOnlyComponent; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -4963,11 +6478,11 @@ export const Exported: TemplateOnlyComponent = ; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -4981,17 +6496,17 @@ export const Exported = as TemplateOnlyComponent; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/js-only.gts 1`] = ` "const num: number = 1; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/mod-var.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -5005,11 +6520,11 @@ const Private: TemplateOnlyComponent = ; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -5023,11 +6538,11 @@ const Private = as TemplateOnlyComponent; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > with semi, without newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, with newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -5047,7 +6562,7 @@ const ModVar1: TemplateOnlyComponent = , num = 1; -\`oops\`; +-\\"oops\\"; const bool: boolean = false, ModVar3: TemplateOnlyComponent = , + ModVar4 = ; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, with newline > it formats ../cases/gts/simple.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gjs/simple.gjs 1`] = ` +"; +-\\"oops\\"; +" +`; + +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/default-export.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; export interface Signature { @@ -5228,37 +6715,36 @@ export interface Signature { } as TemplateOnlyComponent -\`oops\`; -" -`; - -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gjs/js-only.gjs 1`] = ` -"const num = 1\`oops\`; + Explicit default export module top level component. Explicit default export + module top level component. Explicit default export module top level + component. Explicit default export module top level component. Explicit + default export module top level component. + as TemplateOnlyComponent; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gts/default-export.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/exported-mod-var.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + export interface Signature { Element: HTMLElement; Args: {}; Yields: []; } - as TemplateOnlyComponent -\`oops\`; +export const Exported: TemplateOnlyComponent = ; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/exported-mod-var-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + export interface Signature { Element: HTMLElement; Args: {}; @@ -5270,34 +6756,92 @@ export const Exported = as TemplateOnlyComponent; -\`oops\`; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` -"const num: number = 1\`oops\`; +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/js-only.gts 1`] = ` +"const num: number = 1; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/mod-var.gts 1`] = ` +"import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + +export interface Signature { + Element: HTMLElement; + Args: {}; + Yields: []; +} + +const Private: TemplateOnlyComponent = ; +-\\"oops\\"; +" +`; + +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/mod-var-with-as.gts 1`] = ` +"import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + +export interface Signature { + Element: HTMLElement; + Args: {}; + Yields: []; +} + +const Private = as TemplateOnlyComponent; +-\\"oops\\"; +" +`; + +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/multiple-declarations.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + export interface Signature { Element: HTMLElement; Args: {}; Yields: []; } -const Private = as TemplateOnlyComponent; -\`oops\`; +const ModVar1: TemplateOnlyComponent = , + ModVar2: TemplateOnlyComponent = , + num = 1; +-\\"oops\\"; + +const bool: boolean = false, + ModVar3: TemplateOnlyComponent = , + ModVar4: TemplateOnlyComponent = ; +-\\"oops\\"; " `; -exports[`ambiguous > config > default > \`oops\` > without semi, without newline > it formats ../cases/gts/multiple-declarations-with-as.gts 1`] = ` +exports[`ambiguous > config > default > -"oops" > with semi, without newline > it formats ../cases/gts/multiple-declarations-with-as.gts 1`] = ` "import type { TemplateOnlyComponent } from \\"@ember/component/template-only\\"; + export interface Signature { Element: HTMLElement; Args: {}; @@ -5314,7 +6858,8 @@ const ModVar1 =