From 6f9e1125c00e8e837f9203c403dc9473c576de9e Mon Sep 17 00:00:00 2001 From: Ryan Mark Date: Wed, 10 Jul 2019 15:23:51 -0700 Subject: [PATCH] Use `ember-template-recast` to keep existing template formatting --- package-lock.json | 129 +++++- package.json | 6 +- transforms/angle-brackets/test.js | 612 ++++++++++++------------- transforms/angle-brackets/transform.js | 64 +-- 4 files changed, 440 insertions(+), 371 deletions(-) diff --git a/package-lock.json b/package-lock.json index 367e4fb60..314719951 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1497,12 +1497,29 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "async": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "requires": { + "lodash": "^4.17.14" + } + }, "async-limiter": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", "dev": true }, + "async-promise-queue": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/async-promise-queue/-/async-promise-queue-1.0.5.tgz", + "integrity": "sha512-xi0aQ1rrjPWYmqbwr18rrSKbSaXIeIwSd1J4KAgVfkq8utNbdZoht7GfvfY6swFUAMJ9obkc4WPJmtGwl+B8dw==", + "requires": { + "async": "^2.4.1", + "debug": "^2.6.8" + } + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -1855,11 +1872,15 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", - "dev": true, "requires": { "restore-cursor": "^2.0.0" } }, + "cli-spinners": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz", + "integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==" + }, "cli-width": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", @@ -1876,6 +1897,11 @@ "wrap-ansi": "^5.1.0" } }, + "clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" + }, "clone-response": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", @@ -2235,6 +2261,14 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "defaults": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", + "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", + "requires": { + "clone": "^1.0.2" + } + }, "defer-to-connect": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.0.2.tgz", @@ -2356,6 +2390,44 @@ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.264.tgz", "integrity": "sha512-z8E7WkrrquCuGYv+kKyybuZIbdms+4PeHp7Zm2uIgEhAigP0bOwqXILItwj0YO73o+QyHY/7XtEfP5DsHOWQgQ==" }, + "ember-template-recast": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/ember-template-recast/-/ember-template-recast-3.1.3.tgz", + "integrity": "sha512-su7m2IwxydyZ1bggGvRwKTVgccFoKMFFnPi/Zhmb+xPl5Tcu4i7ykcIbZZnGRNUjpYPaqDDffdKIFcswcRWeHQ==", + "requires": { + "@glimmer/syntax": "^0.42.0", + "async-promise-queue": "^1.0.5", + "colors": "^1.3.3", + "commander": "^3.0.0", + "globby": "^10.0.1", + "ora": "^3.4.0", + "tmp": "^0.1.0", + "workerpool": "^3.1.2" + }, + "dependencies": { + "commander": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz", + "integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==" + }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "requires": { + "glob": "^7.1.3" + } + }, + "tmp": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", + "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", + "requires": { + "rimraf": "^2.6.3" + } + } + } + }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", @@ -4939,6 +5011,14 @@ "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", "dev": true }, + "log-symbols": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", + "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "requires": { + "chalk": "^2.0.1" + } + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -5232,6 +5312,11 @@ "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "object-copy": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", @@ -5349,6 +5434,19 @@ } } }, + "ora": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/ora/-/ora-3.4.0.tgz", + "integrity": "sha512-eNwHudNbO1folBP3JsZ19v9azXWtQZjICdr3Q0TDPIaeBQ3mXLrh54wM+er0+hSp+dWKf+Z8KM58CYzEyIYxYg==", + "requires": { + "chalk": "^2.4.2", + "cli-cursor": "^2.1.0", + "cli-spinners": "^2.0.0", + "log-symbols": "^2.2.0", + "strip-ansi": "^5.2.0", + "wcwidth": "^1.0.1" + } + }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", @@ -5551,7 +5649,8 @@ "prettier": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", - "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==" + "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==", + "dev": true }, "prettier-linter-helpers": { "version": "1.0.0", @@ -5911,7 +6010,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", - "dev": true, "requires": { "onetime": "^2.0.0", "signal-exit": "^3.0.2" @@ -5920,14 +6018,12 @@ "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", - "dev": true + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" }, "onetime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", - "dev": true, "requires": { "mimic-fn": "^1.0.0" } @@ -5952,8 +6048,7 @@ "rsvp": { "version": "4.8.5", "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", - "integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==", - "dev": true + "integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==" }, "run-async": { "version": "2.3.0", @@ -6784,6 +6879,14 @@ "makeerror": "1.0.x" } }, + "wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=", + "requires": { + "defaults": "^1.0.3" + } + }, "webidl-conversions": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", @@ -6834,6 +6937,16 @@ "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" }, + "workerpool": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-3.1.2.tgz", + "integrity": "sha512-WJFA0dGqIK7qj7xPTqciWBH5DlJQzoPjsANvc3Y4hNB0SScT+Emjvt0jPPkDBUjBNngX1q9hHgt1Gfwytu6pug==", + "requires": { + "@babel/core": "^7.3.4", + "object-assign": "4.1.1", + "rsvp": "^4.8.4" + } + }, "wrap-ansi": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", diff --git a/package.json b/package.json index 54f627b15..51864b5e9 100644 --- a/package.json +++ b/package.json @@ -31,16 +31,16 @@ ] }, "dependencies": { - "@glimmer/syntax": "^0.42.0", "codemod-cli": "^2.0.0", - "prettier": "^1.18.2" + "ember-template-recast": "^3.1.3" }, "devDependencies": { "coveralls": "^3.0.6", "eslint": "^6.5.0", "eslint-config-prettier": "^6.3.0", "eslint-plugin-prettier": "^3.1.1", - "jest": "^24.9.0" + "jest": "^24.9.0", + "prettier": "^1.18.2" }, "engines": { "node": "^8 || >=10" diff --git a/transforms/angle-brackets/test.js b/transforms/angle-brackets/test.js index 381663fac..75458d358 100644 --- a/transforms/angle-brackets/test.js +++ b/transforms/angle-brackets/test.js @@ -14,9 +14,11 @@ test('action-params', () => { `; expect(runTest('action-params.hbs', input)).toMatchInlineSnapshot(` - " - Button - " + " + + Button + + " `); }); @@ -34,21 +36,13 @@ test('actions', () => { `; expect(runTest('actions.hbs', input)).toMatchInlineSnapshot(` - " - - 1 - - - 2 - - - 3 - - " + " + + 1 + 2 + 3 + + " `); }); @@ -57,9 +51,11 @@ test('boolean-values', () => { {{my-component prop1=true prop2=false}} `; - expect(runTest('true-values.hbs', input)).toMatchInlineSnapshot( - `""` - ); + expect(runTest('true-values.hbs', input)).toMatchInlineSnapshot(` + " + + " + `); }); test('curly', () => { @@ -69,12 +65,10 @@ test('curly', () => { `; expect(runTest('curly.hbs', input)).toMatchInlineSnapshot(` - "
- {{foo}} -
-
- {{{bar}}} -
" + " +
{{foo}}
+
{{{bar}}}
+ " `); }); @@ -109,24 +103,31 @@ test('data-attributes', () => { `; expect(runTest('data-attributes.hbs', input)).toMatchInlineSnapshot(` - " - - - - - - block - - - block - - - block - - - block - - " + " + + + + + + + + block + + + + block + + + + block + + + + block + + + + " `); }); @@ -162,31 +163,17 @@ test('deeply-nested-sub', () => { `; expect(runTest('deeply-nested-sub.hbs', input)).toMatchInlineSnapshot(` - " - help - - - - - - - " + " + + help + + + + + + + + " `); }); @@ -200,11 +187,13 @@ test('each-in', () => { `; expect(runTest('each-in.hbs', input)).toMatchInlineSnapshot(` - "{{#each-in this.people as |name person|}} - Hello,{{name}}! You are{{person.age}}years old. - {{else}} - Sorry, nobody is here. - {{/each-in}}" + " + {{#each-in this.people as |name person|}} + Hello, {{name}}! You are {{person.age}} years old. + {{else}} + Sorry, nobody is here. + {{/each-in}} + " `); }); @@ -215,10 +204,10 @@ test('entities', () => { `; expect(runTest('entities.hbs', input)).toMatchInlineSnapshot(` - "< > × - -  Some text > - " + " + < > × +  Some text > + " `); }); @@ -247,29 +236,28 @@ test('html-tags', () => { `; expect(runTest('html-tags.hbs', input)).toMatchInlineSnapshot(` - " - - -
-
-
" + " + + + + + + +
+ +
+
+ " `); }); @@ -283,11 +271,13 @@ test('if', () => { `; expect(runTest('if.hbs', input)).toMatchInlineSnapshot(` - "{{#if (eq a b)}} - - {{else}} - - {{/if}}" + " + {{#if (eq a b)}} + + {{else}} + + {{/if}} + " `); }); @@ -297,11 +287,9 @@ test('input-helper', () => { `; expect(runTest('input-helper.hbs', input)).toMatchInlineSnapshot(` - "" + " + + " `); }); @@ -319,18 +307,17 @@ test('let', () => { `; expect(runTest('let.hbs', input)).toMatchInlineSnapshot(` - "{{#let - (capitalize this.person.firstName) - (capitalize this.person.lastName) as |firstName lastName| - }} - Welcome back - {{concat firstName \\" \\" lastName}} - Account Details: - First Name: - {{firstName}} - Last Name: - {{lastName}} - {{/let}}" + " + {{#let (capitalize this.person.firstName) (capitalize this.person.lastName) + as |firstName lastName| + }} + Welcome back {{concat firstName ' ' lastName}} + + Account Details: + First Name: {{firstName}} + Last Name: {{lastName}} + {{/let}} + " `); }); @@ -341,12 +328,10 @@ test('link-to', () => { `; expect(runTest('link-to.hbs', input)).toMatchInlineSnapshot(` - " - About Us - - - About Us - " + " + About Us + About Us + " `); }); @@ -378,34 +363,12 @@ test('link-to-inline', () => { `; expect(runTest('link-to-inline.hbs', input)).toMatchInlineSnapshot(` - " - Title - - - Segments - - - Segments - - - {{segment.name}} - " + " + Title + Segments + Segments + {{segment.name}} + " `); }); @@ -417,21 +380,11 @@ test('link-to-model', () => { `; expect(runTest('link-to-model.hbs', input)).toMatchInlineSnapshot(` - " - Read - {{post.title}} - ... - - - Read - {{post.title}} - ... - - - Read - {{post.title}} - ... - " + " + Read {{post.title}}... + Read {{post.title}}... + Read {{post.title}}... + " `); }); @@ -446,18 +399,14 @@ test('link-to-model-array', () => { `; expect(runTest('link-to-model-array.hbs', input)).toMatchInlineSnapshot(` - " - Comment by - {{comment.author.name}} - on - {{comment.date}} - - - Comment by - {{comment.author.name}} - on - {{comment.date}} - " + " + + Comment by {{comment.author.name}} on {{comment.date}} + + + Comment by {{comment.author.name}} on {{comment.date}} + + " `); }); @@ -487,35 +436,24 @@ test('link-to-query-param', () => { `; expect(runTest('link-to-query-param.hbs', input)).toMatchInlineSnapshot(` - " - Recent Posts - - - Recent Posts - - - Recent Posts - - - Recent Posts - - - Recent Posts - - - Users - " + " + + Recent Posts + + + Recent Posts + + + Recent Posts + + + Recent Posts + + + Recent Posts + + Users + " `); }); @@ -532,16 +470,16 @@ test('nested', () => { `; expect(runTest('nested.hbs', input)).toMatchInlineSnapshot(` - " - - - {{#each this.availableCountries as |country|}} - - {{country.name}} - - {{/each}} - - " + " + + + + {{#each this.availableCountries as |country|}} + {{country.name}} + {{/each}} + + + " `); }); @@ -550,9 +488,11 @@ test('null-subexp', () => { {{some-component selected=(is-equal this.bar null)}} `; - expect(runTest('null-subexp.hbs', input)).toMatchInlineSnapshot( - `""` - ); + expect(runTest('null-subexp.hbs', input)).toMatchInlineSnapshot(` + " + + " + `); }); test('positional-params', () => { @@ -569,15 +509,17 @@ test('positional-params', () => { `; expect(runTest('positional-params.hbs', input)).toMatchInlineSnapshot(` - "{{some-component \\"foo\\"}} - {{#some-component \\"foo\\"}} - hi - {{/some-component}} - {{#some-component foo}} - hi - {{/some-component}} - {{some-component 123}} - {{some-component (some-helper 987)}}" + " + {{some-component \\"foo\\"}} + {{#some-component \\"foo\\"}} + hi + {{/some-component}} + {{#some-component foo}} + hi + {{/some-component}} + {{some-component 123}} + {{some-component (some-helper 987)}} + " `); }); @@ -597,17 +539,19 @@ test('sample', () => { `; expect(runTest('sample.hbs', input)).toMatchInlineSnapshot(` - " - - - {{#each this.availableCountries as |country|}} - - {{country.name}} - - {{/each}} - - - " + " + + + + + {{#each this.availableCountries as |country|}} + {{country.name}} + {{/each}} + + + + + " `); }); @@ -624,16 +568,16 @@ test('sample2', () => { `; expect(runTest('sample2.hbs', input)).toMatchInlineSnapshot(` - " - - -

- hello -

-
- - {{card.foo}} -
" + " + + + +

hello

+
+ + {{card.foo}} +
+ " `); }); @@ -642,9 +586,11 @@ test('t-helper', () => { {{t "some.string" param="string" another=1}} `; - expect(runTest('t-helper.hbs', input)).toMatchInlineSnapshot( - `"{{t \\"some.string\\" param=\\"string\\" another=1}}"` - ); + expect(runTest('t-helper.hbs', input)).toMatchInlineSnapshot(` + " + {{t \\"some.string\\" param=\\"string\\" another=1}} + " + `); }); test('tag-name', () => { @@ -652,7 +598,11 @@ test('tag-name', () => { {{foo/bar name=""}} `; - expect(runTest('tag-name.hbs', input)).toMatchInlineSnapshot(`""`); + expect(runTest('tag-name.hbs', input)).toMatchInlineSnapshot(` + " + + " + `); }); test('textarea', () => { @@ -660,9 +610,11 @@ test('textarea', () => { {{textarea value=this.model.body}} `; - expect(runTest('textarea.hbs', input)).toMatchInlineSnapshot( - `"