forked from alangpierce/sucrase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address code review comments, other updates
* Get rid of simple source map mode. For now, the detailed source maps will be the only mode. Also inline `computeDetailedSourceMap` now that it's the only case. * Remove `WRITE_SOURCE_MAPS` in test and related details. In alangpierce#793 I added source map info to the demo website, which is a nicer system for manually verifying correctness. * Update test code to assert the full source map and a JSON representation of the mappings. * Add integration test for Jest inline snapshots. * Change lint config to ignore unused rest siblings. * Add bounds checks and change empty `for` loops to `while` (just a style preference). * Add comments in a few more places. * Remove unnecessary special case when handling hashbang lines.
- Loading branch information
1 parent
186ba58
commit aa3e9a9
Showing
14 changed files
with
135 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,3 @@ integrations/gulp-plugin/dist | |
coverage.lcov | ||
benchmark/sample/jest | ||
.perf-comparison | ||
test/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Other integration test cases | ||
|
||
Tests in this folder help power test cases that don't fit nicely into the usual | ||
framework of discovering and running each project as a test case. These projects | ||
are referenced directly by tests. |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/other-cases/allows-inline-snapshots/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
transform: {"\\.(js|jsx|ts|tsx)$": "@sucrase/jest-plugin"}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/other-cases/allows-inline-snapshots/main.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test("fills inline snapshot", () => { | ||
expect(3 as number).toMatchInlineSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,70 @@ | ||
import {eachMapping, TraceMap, SourceMapInput, EachMapping} from "@jridgewell/trace-mapping"; | ||
import * as assert from "assert"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
import {transform} from "../src"; | ||
|
||
describe("source maps", () => { | ||
const testCase = (simple: boolean): void => { | ||
it("generates a detailed line-based source map", () => { | ||
const source = `\ | ||
import a from "./a"; | ||
const x: number = 1; | ||
const x: number = a; | ||
console.log(x + 1); | ||
`; | ||
const result = transform(source, { | ||
transforms: ["imports", "typescript"], | ||
sourceMapOptions: {compiledFilename: "test.js", simple}, | ||
sourceMapOptions: {compiledFilename: "test.js"}, | ||
filePath: "test.ts", | ||
}); | ||
const simpleMappings = "AAAA;AACA;AACA;AACA"; | ||
assert.equal( | ||
result.code, | ||
`"use strict"; function _interopRequireDefault(obj) { \ | ||
return obj && obj.__esModule ? obj : { default: obj }; } \ | ||
var _a = require('./a'); var _a2 = _interopRequireDefault(_a); | ||
const x = _a2.default; | ||
console.log(x + 1); | ||
`, | ||
); | ||
assert.deepEqual(result.sourceMap, { | ||
version: 3, | ||
sources: ["test.ts"], | ||
names: [], | ||
mappings: simple ? simpleMappings : result.sourceMap!.mappings, | ||
mappings: `AAAA,mHAAM,8DAAmB;AACzB,MAAM,MAAM,CAAC,CAAS,EAAE,WAAC;AACzB,\ | ||
MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AACxB`, | ||
file: "test.js", | ||
}); | ||
if (!simple) { | ||
if (process.env.WRITE_SOURCE_MAPS) { | ||
const outDir = path.join(__dirname, "output"); | ||
fs.mkdirSync(outDir, {recursive: true}); | ||
result.sourceMap!.sourcesContent = [source]; | ||
let suffix = "//# sourceMapping"; | ||
suffix += `URL=test.js.map`; | ||
fs.writeFileSync(path.join(outDir, "test.js"), `${result.code}\n${suffix}`); | ||
fs.writeFileSync(path.join(outDir, "test.js.map"), JSON.stringify(result.sourceMap)); | ||
} | ||
const {mappings} = result.sourceMap!; | ||
assert.match(mappings, /^[^;]+(;[^;]+){3}$/); // 4 lines | ||
assert.notEqual(mappings, simpleMappings); | ||
} | ||
}; | ||
it("generates a simple line-based source map", () => { | ||
testCase(true); | ||
}); | ||
it("generates a detailed line-based source map", () => { | ||
testCase(false); | ||
const traceMap = new TraceMap(result.sourceMap as SourceMapInput); | ||
const mappings: Array< | ||
Pick<EachMapping, "generatedLine" | "generatedColumn" | "originalLine" | "originalColumn"> | ||
> = []; | ||
eachMapping(traceMap, ({generatedLine, generatedColumn, originalLine, originalColumn}) => { | ||
mappings.push({generatedLine, generatedColumn, originalLine, originalColumn}); | ||
}); | ||
assert.deepEqual( | ||
mappings, | ||
[ | ||
{generatedLine: 1, generatedColumn: 0, originalLine: 1, originalColumn: 0}, | ||
{generatedLine: 1, generatedColumn: 115, originalLine: 1, originalColumn: 6}, | ||
{generatedLine: 1, generatedColumn: 177, originalLine: 1, originalColumn: 25}, | ||
{generatedLine: 2, generatedColumn: 0, originalLine: 2, originalColumn: 0}, | ||
{generatedLine: 2, generatedColumn: 6, originalLine: 2, originalColumn: 6}, | ||
{generatedLine: 2, generatedColumn: 12, originalLine: 2, originalColumn: 12}, | ||
{generatedLine: 2, generatedColumn: 13, originalLine: 2, originalColumn: 13}, | ||
{generatedLine: 2, generatedColumn: 14, originalLine: 2, originalColumn: 22}, | ||
{generatedLine: 2, generatedColumn: 16, originalLine: 2, originalColumn: 24}, | ||
{generatedLine: 2, generatedColumn: 27, originalLine: 2, originalColumn: 25}, | ||
{generatedLine: 3, generatedColumn: 0, originalLine: 3, originalColumn: 0}, | ||
{generatedLine: 3, generatedColumn: 6, originalLine: 3, originalColumn: 6}, | ||
{generatedLine: 3, generatedColumn: 13, originalLine: 3, originalColumn: 13}, | ||
{generatedLine: 3, generatedColumn: 14, originalLine: 3, originalColumn: 14}, | ||
{generatedLine: 3, generatedColumn: 17, originalLine: 3, originalColumn: 17}, | ||
{generatedLine: 3, generatedColumn: 18, originalLine: 3, originalColumn: 18}, | ||
{generatedLine: 3, generatedColumn: 20, originalLine: 3, originalColumn: 20}, | ||
{generatedLine: 3, generatedColumn: 22, originalLine: 3, originalColumn: 22}, | ||
{generatedLine: 3, generatedColumn: 23, originalLine: 3, originalColumn: 23}, | ||
{generatedLine: 3, generatedColumn: 24, originalLine: 3, originalColumn: 24}, | ||
{generatedLine: 4, generatedColumn: 0, originalLine: 4, originalColumn: 0}, | ||
], | ||
`Expected:\n${mappings.map((m) => `${JSON.stringify(m)},`).join("\n")}`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters