From 9acf08a06eae1d77dd05ea7f11938866e7a44a2b Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 27 May 2020 17:12:27 +0200 Subject: [PATCH 1/5] init --- src/compiler/compile/utils/hash.ts | 1 + test/css/index.js | 3 ++- test/custom-elements/index.js | 4 ++-- test/js/index.js | 6 +++--- test/parser/index.js | 10 +++------- test/runtime/index.js | 4 ++-- test/server-side-rendering/index.js | 4 ++-- test/validator/index.js | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/compiler/compile/utils/hash.ts b/src/compiler/compile/utils/hash.ts index 7ac892611bd7..190904cc6fc5 100644 --- a/src/compiler/compile/utils/hash.ts +++ b/src/compiler/compile/utils/hash.ts @@ -1,5 +1,6 @@ // https://github.com/darkskyapp/string-hash/blob/master/index.js export default function hash(str: string): string { + str = str.replace(/\r/g, "") let hash = 5381; let i = str.length; diff --git a/test/css/index.js b/test/css/index.js index dc17314597fa..81d27a94bf85 100644 --- a/test/css/index.js +++ b/test/css/index.js @@ -56,7 +56,8 @@ describe('css', () => { const config = try_require(`./samples/${dir}/_config.js`) || {}; const input = fs .readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8') - .replace(/\s+$/, ''); + .replace(/\s+$/, '') + .replace(/\r/g, ''); const expected_warnings = (config.warnings || []).map(normalize_warning); diff --git a/test/custom-elements/index.js b/test/custom-elements/index.js index d68d3b94c58e..b1bdf482191d 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.js @@ -63,7 +63,7 @@ describe('custom-elements', function() { const warnings = []; (solo ? it.only : skip ? it.skip : it)(dir, async () => { - const config = loadConfig(`./custom-elements/samples/${dir}/_config.js`); + const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); const expected_warnings = config.warnings || []; const bundle = await rollup({ @@ -82,7 +82,7 @@ describe('custom-elements', function() { transform(code, id) { if (id.endsWith('.svelte')) { - const compiled = svelte.compile(code, { + const compiled = svelte.compile(code.replace(/\r/g, ""), { customElement: true, dev: config.dev }); diff --git a/test/js/index.js b/test/js/index.js index d4ea13ad9832..8aa4cc76a936 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -25,7 +25,7 @@ describe("js", () => { (solo ? it.only : it)(dir, () => { const config = loadConfig(`${resolved}/_config.js`); - const input = fs.readFileSync(`${resolved}/input.svelte`, "utf-8").replace(/\s+$/, ""); + const input = fs.readFileSync(`${resolved}/input.svelte`, "utf-8").replace(/\s+$/, "").replace(/\r/g, ""); let actual; @@ -56,8 +56,8 @@ describe("js", () => { try { assert.equal( - actual.trim().replace(/^[ \t]+$/gm, ""), - expected.trim().replace(/^[ \t]+$/gm, "") + actual.trim().replace(/^[ \t]+$/gm, "").replace(/\r/g, ""), + expected.trim().replace(/^[ \t]+$/gm, "").replace(/\r/g, "") ); } catch (error) { if (shouldUpdateExpected()) { diff --git a/test/parser/index.js b/test/parser/index.js index 27c5ec1563ce..2c8d516a7d84 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -20,7 +20,7 @@ describe('parse', () => { (skip ? it.skip : solo ? it.only : it)(dir, () => { const options = tryToLoadJson(`${__dirname}/samples/${dir}/options.json`) || {}; - const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, ''); + const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, '').replace(/\r/g, ""); const expectedOutput = tryToLoadJson(`${__dirname}/samples/${dir}/output.json`); const expectedError = tryToLoadJson(`${__dirname}/samples/${dir}/error.json`); @@ -38,13 +38,9 @@ describe('parse', () => { } catch (err) { if (err.name !== 'ParseError') throw err; if (!expectedError) throw err; - + const { code, message, pos, start } = err try { - assert.equal(err.code, expectedError.code); - assert.equal(err.message, expectedError.message); - assert.deepEqual(err.start, expectedError.start); - assert.equal(err.pos, expectedError.pos); - assert.equal(err.toString().split('\n')[0], `${expectedError.message} (${expectedError.start.line}:${expectedError.start.column})`); + assert.deepEqual({ code, message, pos, start }, expectedError); } catch (err2) { const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2; throw e; diff --git a/test/runtime/index.js b/test/runtime/index.js index f070eb818551..65157196c9d7 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -39,7 +39,7 @@ describe("runtime", () => { filename }, compileOptions); - const { js: { code } } = compile(fs.readFileSync(filename, "utf-8"), options); + const { js: { code } } = compile(fs.readFileSync(filename, "utf-8").replace(/\r/g, ""), options); return module._compile(code, filename); }; @@ -103,7 +103,7 @@ describe("runtime", () => { try { const { js } = compile( - fs.readFileSync(`${cwd}/${file}`, 'utf-8'), + fs.readFileSync(`${cwd}/${file}`, 'utf-8').replace(/\r/g, ""), { ...compileOptions, filename: file diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.js index ee1319845dfe..2d539782ffa8 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.js @@ -88,8 +88,8 @@ describe("ssr", () => { try { assert.equal( - css.code.replace(/^\s+/gm, ""), - expectedCss.replace(/^\s+/gm, "") + css.code.replace(/^\s+/gm, "").replace(/[\r\n]/g, ""), + expectedCss.replace(/^\s+/gm, "").replace(/[\r\n]/g, "") ); } catch (error) { if (shouldUpdateExpected()) { diff --git a/test/validator/index.js b/test/validator/index.js index 9bce5e149b4a..433e1a94ae6b 100644 --- a/test/validator/index.js +++ b/test/validator/index.js @@ -17,7 +17,7 @@ describe("validate", () => { (solo ? it.only : skip ? it.skip : it)(dir, () => { const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); - const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, ""); + const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, "").replace(/\r/g, ""); const expected_warnings = tryToLoadJson(`${__dirname}/samples/${dir}/warnings.json`) || []; const expected_errors = tryToLoadJson(`${__dirname}/samples/${dir}/errors.json`); const options = tryToLoadJson(`${__dirname}/samples/${dir}/options.json`); From 34f946894e3e4713247c385fc29c2529ea0090b4 Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 27 May 2020 17:14:22 +0200 Subject: [PATCH 2/5] lint --- src/compiler/compile/utils/hash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compile/utils/hash.ts b/src/compiler/compile/utils/hash.ts index 190904cc6fc5..e10013aca218 100644 --- a/src/compiler/compile/utils/hash.ts +++ b/src/compiler/compile/utils/hash.ts @@ -1,6 +1,6 @@ // https://github.com/darkskyapp/string-hash/blob/master/index.js export default function hash(str: string): string { - str = str.replace(/\r/g, "") + str = str.replace(/\r/g, ""); let hash = 5381; let i = str.length; From b1556ea3b5c66b25df0fa7a8ff490a0160e39cff Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 27 May 2020 19:41:59 +0200 Subject: [PATCH 3/5] remove autocrlf from actions & readme --- .github/workflows/ci.yml | 1 - README.md | 5 ----- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a50cae9ba66..ff0ec4f633e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,6 @@ jobs: node-version: [8, 10, 12, 14] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - - run: git config --global core.autocrlf false - uses: actions/checkout@v1 - uses: actions/setup-node@v1 with: diff --git a/README.md b/README.md index 0d9b59a4cc6a..e2e4fcd53247 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,6 @@ npm install > Do not use Yarn to install the dependencies, as the specific package versions in `package-lock.json` are used to build and test Svelte. -> Many tests depend on newlines being preserved as ``. On Windows, you can ensure this by cloning with: -> ```bash -> git -c core.autocrlf=false clone https://github.com/sveltejs/svelte.git -> ``` - To build the compiler, and all the other modules included in the package: ```bash From 9cbd760d86263b391d1d6718404cd59f22e6109d Mon Sep 17 00:00:00 2001 From: pushkine Date: Thu, 28 May 2020 02:09:46 +0200 Subject: [PATCH 4/5] add error `end` check --- test/parser/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parser/index.js b/test/parser/index.js index 2c8d516a7d84..a7b0907dc5cf 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -38,9 +38,9 @@ describe('parse', () => { } catch (err) { if (err.name !== 'ParseError') throw err; if (!expectedError) throw err; - const { code, message, pos, start } = err + const { code, message, pos, start, end } = err; try { - assert.deepEqual({ code, message, pos, start }, expectedError); + assert.deepEqual({ code, message, pos, start, end }, expectedError); } catch (err2) { const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2; throw e; From 8fabca902803d12f928fbe65ce4c3f68289f761e Mon Sep 17 00:00:00 2001 From: pushkine Date: Thu, 28 May 2020 02:16:21 +0200 Subject: [PATCH 5/5] Revert "add error `end` check" This reverts commit 9cbd760d86263b391d1d6718404cd59f22e6109d. --- test/parser/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parser/index.js b/test/parser/index.js index a7b0907dc5cf..2c8d516a7d84 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -38,9 +38,9 @@ describe('parse', () => { } catch (err) { if (err.name !== 'ParseError') throw err; if (!expectedError) throw err; - const { code, message, pos, start, end } = err; + const { code, message, pos, start } = err try { - assert.deepEqual({ code, message, pos, start, end }, expectedError); + assert.deepEqual({ code, message, pos, start }, expectedError); } catch (err2) { const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2; throw e;