From 64050e6a6345b171a35f81833367ba486ca13338 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 6 Jun 2024 10:09:55 +0200 Subject: [PATCH] Updates to satisfy linter Also makes the linter ignore the submodule --- package.json | 2 +- test/test-spec-tests.js | 123 +++++++++++++++++++++++++++++----------- 2 files changed, 92 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 3301cbdd..ae0e6552 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ }, "license": "BSD-3-Clause", "scripts": { - "lint": "eslint --fix *.js lib/ test/", + "lint": "eslint --fix *.js lib/ test/ --ignore-pattern 'test/source-map-tests/**'", "test": "git submodule update --init --recursive; node test/run-tests.js", "coverage": "c8 --reporter=text --reporter=html npm test", "prettier": "prettier --write .", diff --git a/test/test-spec-tests.js b/test/test-spec-tests.js index 12fc2cea..fbe29117 100644 --- a/test/test-spec-tests.js +++ b/test/test-spec-tests.js @@ -5,7 +5,7 @@ * http://opensource.org/licenses/BSD-3-Clause */ -const fs = require('node:fs/promises'); +const fs = require("node:fs/promises"); const SourceMapConsumer = require("../lib/source-map-consumer").SourceMapConsumer; @@ -50,7 +50,7 @@ const skippedTests = [ "ignoreListWrongType2", "ignoreListWrongType3", "ignoreListOutOfBounds", -] +]; // The source-map library converts null sources to the "null" URL in its // sources list, so for equality checking we accept this as null. @@ -66,37 +66,68 @@ function mapLine(line) { } async function testMappingAction(assert, rawSourceMap, action) { - return SourceMapConsumer.with(rawSourceMap, null, (consumer) => { - mappedPosition = consumer.originalPositionFor({ + return SourceMapConsumer.with(rawSourceMap, null, consumer => { + let mappedPosition = consumer.originalPositionFor({ line: mapLine(action.generatedLine), column: action.generatedColumn, }); - assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); - assert.equal(nullish(mappedPosition.source), action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); - if (action.mappedName) - assert.equal(mappedPosition.name, action.mappedName, `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}`); + assert.equal( + mappedPosition.line, + mapLine(action.originalLine), + `original line didn't match, expected ${mapLine( + action.originalLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.originalColumn, + `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}` + ); + assert.equal( + nullish(mappedPosition.source), + action.originalSource, + `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}` + ); + if (action.mappedName) { + assert.equal( + mappedPosition.name, + action.mappedName, + `mapped name didn't match, expected ${action.mappedName} got ${mappedPosition.name}` + ); + } // When the source is null, a reverse lookup may not make sense // because there isn't a unique way to look it up. if (action.originalSource !== null) { - let mappedPosition = consumer.generatedPositionFor({ + mappedPosition = consumer.generatedPositionFor({ source: action.originalSource, line: mapLine(action.originalLine), - column: action.originalColumn + column: action.originalColumn, }); - assert.equal(mappedPosition.line, mapLine(action.generatedLine), `generated line didn't match, expected ${mapLine(action.generatedLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.generatedColumn, `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}`); + assert.equal( + mappedPosition.line, + mapLine(action.generatedLine), + `generated line didn't match, expected ${mapLine( + action.generatedLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.generatedColumn, + `generated column didn't match, expected ${action.generatedColumn} got ${mappedPosition.column}` + ); } - }); } async function testTransitiveMappingAction(assert, rawSourceMap, action) { - return SourceMapConsumer.with(rawSourceMap, null, async (consumer) => { - assert.ok(Array.isArray(action.intermediateMaps), "transitive mapping case requires intermediate maps"); + return SourceMapConsumer.with(rawSourceMap, null, async consumer => { + assert.ok( + Array.isArray(action.intermediateMaps), + "transitive mapping case requires intermediate maps" + ); let mappedPosition = consumer.originalPositionFor({ line: mapLine(action.generatedLine), @@ -104,38 +135,66 @@ async function testTransitiveMappingAction(assert, rawSourceMap, action) { }); for (const intermediateMapPath of action.intermediateMaps) { - const intermediateMap = await readJSON(`./source-map-tests/resources/${intermediateMapPath}`); - await SourceMapConsumer.with(intermediateMap, null, (consumer) => { - mappedPosition = consumer.originalPositionFor({ - line: mappedPosition.line, - column: mappedPosition.column, - }); - }); + const intermediateMap = await readJSON( + `./source-map-tests/resources/${intermediateMapPath}` + ); + await SourceMapConsumer.with( + intermediateMap, + null, + consumerIntermediate => { + mappedPosition = consumerIntermediate.originalPositionFor({ + line: mappedPosition.line, + column: mappedPosition.column, + }); + } + ); } - assert.equal(mappedPosition.line, mapLine(action.originalLine), `original line didn't match, expected ${mapLine(action.originalLine)} got ${mappedPosition.line}`); - assert.equal(mappedPosition.column, action.originalColumn, `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}`); - assert.equal(mappedPosition.source, action.originalSource, `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}`); + assert.equal( + mappedPosition.line, + mapLine(action.originalLine), + `original line didn't match, expected ${mapLine( + action.originalLine + )} got ${mappedPosition.line}` + ); + assert.equal( + mappedPosition.column, + action.originalColumn, + `original column didn't match, expected ${action.originalColumn} got ${mappedPosition.column}` + ); + assert.equal( + mappedPosition.source, + action.originalSource, + `original source didn't match, expected ${action.originalSource} got ${mappedPosition.source}` + ); }); } for (const testCase of sourceMapSpecTests.tests) { - if (skippedTests.includes(testCase.name)) + if (skippedTests.includes(testCase.name)) { continue; + } exports[`test from source map spec tests, name: ${testCase.name}`] = async function (assert) { - const json = await readJSON(`./source-map-tests/resources/${testCase.sourceMapFile}`); + const json = await readJSON( + `./source-map-tests/resources/${testCase.sourceMapFile}` + ); try { const map = await new SourceMapConsumer(json); map.eachMapping(() => {}); map.destroy(); } catch (exn) { - if (testCase.sourceMapIsValid) - assert.fail("Expected valid source map but failed to load successfully: " + exn.message); + if (testCase.sourceMapIsValid) { + assert.fail( + "Expected valid source map but failed to load successfully: " + + exn.message + ); + } return; } - if (!testCase.sourceMapIsValid) + if (!testCase.sourceMapIsValid) { assert.fail("Expected invalid source map but loaded successfully"); + } if (testCase.testActions) { for (const testAction of testCase.testActions) { if (testAction.actionType == "checkMapping") { @@ -146,4 +205,4 @@ for (const testCase of sourceMapSpecTests.tests) { } } }; -}; +}