-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI flags for all Sucrase options (#812)
Supersedes #670 Progress toward #792 This PR adds to the CLI a number of options that had been added. The CLI could still use some work in terms of error reporting and behavior, but this should hopefully get it closer to parity with other use cases. The CLI previously had no tests, so this also adds an integration test suite exercising each new and existing Sucrase option (though it's not yet at full coverage).
- Loading branch information
1 parent
7c8f270
commit d617368
Showing
28 changed files
with
183 additions
and
10 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
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-disable-es-transforms/dist-expected/main.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,4 @@ | ||
class A { | ||
x = 1; | ||
constructor( y) {;this.y = y;} | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-disable-es-transforms/src/main.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,4 @@ | ||
class A { | ||
x: number = 1; | ||
constructor(readonly y: string) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-disable-es-transforms/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms typescript --disable-es-transforms" | ||
} |
6 changes: 6 additions & 0 deletions
6
...t-cases/cli-cases/respects-inject-create-require-for-import-require/dist-expected/main.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,6 @@ | ||
import {createRequire as _createRequire} from "module"; const _require = _createRequire(import.meta.url); | ||
const A = _require('../A'); | ||
|
||
function foo() { | ||
console.log(A); | ||
} |
6 changes: 6 additions & 0 deletions
6
...n-test/test-cases/cli-cases/respects-inject-create-require-for-import-require/src/main.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,6 @@ | ||
|
||
import A = require('../A'); | ||
|
||
function foo(): void { | ||
console.log(A); | ||
} |
3 changes: 3 additions & 0 deletions
3
...ion-test/test-cases/cli-cases/respects-inject-create-require-for-import-require/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms typescript --inject-create-require-for-import-require" | ||
} |
5 changes: 5 additions & 0 deletions
5
integration-test/test-cases/cli-cases/respects-jsx-defaults/dist-expected/main.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,5 @@ | ||
const _jsxFileName = "src/main.jsx";import React from 'react'; | ||
|
||
function Foo() { | ||
return React.createElement(React.Fragment, null, React.createElement('div', {__self: this, __source: {fileName: _jsxFileName, lineNumber: 4}} )); | ||
} |
5 changes: 5 additions & 0 deletions
5
integration-test/test-cases/cli-cases/respects-jsx-defaults/src/main.jsx
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 @@ | ||
import React from 'react'; | ||
|
||
function Foo() { | ||
return <><div /></>; | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-defaults/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms jsx" | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-jsx-runtime-automatic/dist-expected/main.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,4 @@ | ||
const _jsxFileName = "src/main.tsx";import {jsxDEV as _jsxDEV} from "preact/jsx-dev-runtime"; | ||
function Foo() { | ||
return _jsxDEV('div', {}, void 0, false, {fileName: _jsxFileName, lineNumber: 3}, this ); | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-jsx-runtime-automatic/src/main.tsx
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,4 @@ | ||
|
||
function Foo(): JSX.Element { | ||
return <div />; | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-runtime-automatic/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms jsx,typescript --jsx-runtime automatic --jsx-import-source preact" | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-jsx-runtime-classic/dist-expected/main.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,4 @@ | ||
|
||
function Foo() { | ||
return h(React.Fragment, null, h('div', null )); | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-jsx-runtime-classic/src/main.jsx
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,4 @@ | ||
|
||
function Foo() { | ||
return <><div /></>; | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-runtime-classic/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms jsx --production --jsx-pragma h jsx-fragment-pragma Frag" | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-runtime-preserve/dist-expected/main.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 @@ | ||
function Foo() { | ||
return <div />; | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-runtime-preserve/src/main.tsx
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 @@ | ||
function Foo(): JSX.Element { | ||
return <div />; | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-jsx-runtime-preserve/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms jsx,typescript --jsx-runtime preserve" | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-keep-unused-imports/dist-expected/main.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,4 @@ | ||
import A from '../A'; | ||
import B from '../B'; | ||
|
||
console.log(A); |
4 changes: 4 additions & 0 deletions
4
integration-test/test-cases/cli-cases/respects-keep-unused-imports/src/main.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,4 @@ | ||
import A from '../A'; | ||
import B from '../B'; | ||
|
||
console.log(A); |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-keep-unused-imports/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms typescript --keep-unused-imports" | ||
} |
6 changes: 6 additions & 0 deletions
6
integration-test/test-cases/cli-cases/respects-preserve-dynamic-import/dist-expected/main.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,6 @@ | ||
"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _A = require('../A'); var _A2 = _interopRequireDefault(_A); | ||
|
||
async function foo() { | ||
const B = (await import("../B")).default; | ||
console.log(_A2.default + B); | ||
} |
6 changes: 6 additions & 0 deletions
6
integration-test/test-cases/cli-cases/respects-preserve-dynamic-import/src/main.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,6 @@ | ||
import A from "../A"; | ||
|
||
async function foo() { | ||
const B = (await import("../B")).default; | ||
console.log(A + B); | ||
} |
3 changes: 3 additions & 0 deletions
3
integration-test/test-cases/cli-cases/respects-preserve-dynamic-import/test.json
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 @@ | ||
{ | ||
"cliOptions": "--transforms imports --preserve-dynamic-import" | ||
} |
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,27 @@ | ||
import * as assert from "assert"; | ||
import {readdir, readFile, stat} from "fs/promises"; | ||
import {join} from "path"; | ||
|
||
export default async function assertDirectoriesEqual(dir1: string, dir2: string): Promise<void> { | ||
const dir1Files = (await readdir(dir1)).sort(); | ||
const dir2Files = (await readdir(dir2)).sort(); | ||
assert.strictEqual( | ||
dir1Files.join(", "), | ||
dir2Files.join(", "), | ||
`Unexpected different lists of files for directories:\n${dir1}\n${dir2}`, | ||
); | ||
for (const filename of dir1Files) { | ||
const path1 = join(dir1, filename); | ||
const path2 = join(dir2, filename); | ||
const isDir1 = (await stat(path1)).isDirectory(); | ||
const isDir2 = (await stat(path2)).isDirectory(); | ||
assert.strictEqual(isDir1, isDir2, `Paths are different types:\n${path1}\n${path2}`); | ||
if (isDir1) { | ||
await assertDirectoriesEqual(path1, path2); | ||
} else { | ||
const contents1 = (await readFile(path1)).toString(); | ||
const contents2 = (await readFile(path2)).toString(); | ||
assert.strictEqual(contents1, contents2, `File contents differed:\n${path1}\n${path2}`); | ||
} | ||
} | ||
} |
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