mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 22:46:54 +08:00
remove the strict option entirely
This commit is contained in:
24
CHANGELOG.md
24
CHANGELOG.md
@@ -10,6 +10,30 @@ The breaking changes are as follows:
|
||||
|
||||
For the transform API, the return values `js` and `jsSourceMap` have been renamed to `code` and `map` respectively. This is because esbuild now supports CSS as a first-class content type, and returning CSS code in a variable called `js` made no sense.
|
||||
|
||||
* The class field transform is now more accurate
|
||||
|
||||
Class fields look like this:
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
foo = 123
|
||||
}
|
||||
```
|
||||
|
||||
Previously the transform for class fields used a normal assignment for initialization:
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
constructor() {
|
||||
this.foo = 123;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
However, this doesn't exactly follow the initialization behavior in the JavaScript specification. For example, it can cause a setter to be called if one exists with that property name, which isn't supposed to happen. A more accurate transform that used `Object.defineProperty()` instead was available under the `--strict:class-fields` option.
|
||||
|
||||
This release removes the `--strict:class-fields` option and makes that the default behavior. There is no longer a way to compile class fields to normal assignments instead, since that doesn't follow JavaScript semantics. Note that for legacy reasons, TypeScript code will still compile class fields to normal assignments unless `useDefineForClassFields` is enabled in `tsconfig.json` just like the official TypeScript compiler.
|
||||
|
||||
* When bundling stdin using the API, `resolveDir` is now required to resolve imports
|
||||
|
||||
The `resolveDir` option specifies the directory to resolve relative imports against. Previously it defaulted to the current working directory. Now it no longer does, so you must explicitly specify it if you need it:
|
||||
|
||||
41
README.md
41
README.md
@@ -157,48 +157,10 @@ These syntax features are conditionally transformed for older browsers depending
|
||||
|
||||
The expression `a?.b` is transformed into `a == null ? void 0 : a.b`, which works because `a == null` is only true if `a` is neither `null` nor `undefined`. However, there's exactly one obscure edge case where this doesn't work. For legacy reasons, the value of `document.all` is special-cased such that `document.all == null` is true. It is assumed that if you are using the `?.` syntax, your code is new enough that it doesn't need to manipulate `document.all`.
|
||||
|
||||
* **Class field correctness**
|
||||
|
||||
Class fields look like this:
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
foo = 123
|
||||
}
|
||||
```
|
||||
|
||||
By default, the transform for class fields uses a normal assignment for initialization. That looks like this:
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
constructor() {
|
||||
this.foo = 123;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This doesn't increase code size by much and stays on the heavily-optimized path for modern JavaScript JITs. It also matches the default behavior of the TypeScript compiler. However, this doesn't exactly follow the initialization behavior in the JavaScript specification. For example, it can cause a setter to be called if one exists with that property name, which isn't supposed to happen. A more accurate transformation would be to use `Object.defineProperty()` instead like this:
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
constructor() {
|
||||
Object.defineProperty(this, "foo", {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: 123
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This increases code size and decreases performance, but follows the JavaScript specification more accurately. If you need this accuracy, you should either enable the `--strict:class-fields` option or add the `useDefineForClassFields` flag to your `tsconfig.json` file.
|
||||
|
||||
* **Private member performance**
|
||||
|
||||
This transform uses `WeakMap` and `WeakSet` to preserve the privacy properties of this feature, similar to the corresponding transforms in the Babel and TypeScript compilers. Most modern JavaScript engines (V8, JavaScriptCore, and SpiderMonkey but not ChakraCore) may not have good performance characteristics for large `WeakMap` and `WeakSet` objects. Creating many instances of classes with private fields or private methods with this syntax transform active may cause a lot of overhead for the garbage collector. This is because modern engines (other than ChakraCore) store weak values in an actual map object instead of as hidden properties on the keys themselves, and large map objects can cause performance issues with garbage collection. See [this reference](https://github.com/tc39/ecma262/issues/1657#issuecomment-518916579) for more information.
|
||||
|
||||
Note that if you want to enable strictness for all transforms, you can just pass `--strict` instead of using `--strict:...` for each transform.
|
||||
</details>
|
||||
|
||||
These syntax features are currently always passed through un-transformed:
|
||||
@@ -391,9 +353,6 @@ Advanced options:
|
||||
--resolve-extensions=... A comma-separated list of implicit extensions
|
||||
(default ".tsx,.ts,.jsx,.mjs,.cjs,.js,.css,.json")
|
||||
--metafile=... Write metadata about the build to a JSON file
|
||||
--strict Transforms handle edge cases but have more overhead
|
||||
(enable individually using --strict:X where X is
|
||||
one of: class-fields)
|
||||
--pure:N Mark the name N as a pure function for tree shaking
|
||||
--inject:F Import the file F into all input files and
|
||||
automatically replace matching globals with imports
|
||||
|
||||
@@ -55,9 +55,6 @@ Advanced options:
|
||||
--resolve-extensions=... A comma-separated list of implicit extensions
|
||||
(default ".tsx,.ts,.jsx,.mjs,.cjs,.js,.css,.json")
|
||||
--metafile=... Write metadata about the build to a JSON file
|
||||
--strict Transforms handle edge cases but have more overhead
|
||||
(enable individually using --strict:X where X is
|
||||
one of: class-fields)
|
||||
--pure:N Mark the name N as a pure function for tree shaking
|
||||
--inject:F Import the file F into all input files and
|
||||
automatically replace matching globals with imports
|
||||
|
||||
@@ -567,8 +567,8 @@ func ScanBundle(log logger.Log, fs fs.FS, res resolver.Resolver, entryPaths []st
|
||||
if len(resolveResult.JSXFragment) > 0 {
|
||||
optionsClone.JSX.Fragment = resolveResult.JSXFragment
|
||||
}
|
||||
if resolveResult.StrictClassFields {
|
||||
optionsClone.Strict.ClassFields = true
|
||||
if resolveResult.UseDefineForClassFieldsTS {
|
||||
optionsClone.UseDefineForClassFields = true
|
||||
}
|
||||
if resolveResult.PreserveUnusedImportsTS {
|
||||
optionsClone.PreserveUnusedImportsTS = true
|
||||
|
||||
@@ -943,33 +943,6 @@ func TestLowerAsyncSuperES2016NoBundle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestLowerClassFieldStrict2020NoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
"/entry.js": `
|
||||
class Foo {
|
||||
#foo = 123
|
||||
#bar
|
||||
foo = 123
|
||||
bar
|
||||
static #s_foo = 123
|
||||
static #s_bar
|
||||
static s_foo = 123
|
||||
static s_bar
|
||||
}
|
||||
`,
|
||||
},
|
||||
entryPaths: []string{"/entry.js"},
|
||||
options: config.Options{
|
||||
UnsupportedJSFeatures: es(2020),
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: true,
|
||||
},
|
||||
AbsOutputFile: "/out.js",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestLowerClassField2020NoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
@@ -994,32 +967,6 @@ func TestLowerClassField2020NoBundle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestLowerClassFieldStrictNextNoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
"/entry.js": `
|
||||
class Foo {
|
||||
#foo = 123
|
||||
#bar
|
||||
foo = 123
|
||||
bar
|
||||
static #s_foo = 123
|
||||
static #s_bar
|
||||
static s_foo = 123
|
||||
static s_bar
|
||||
}
|
||||
`,
|
||||
},
|
||||
entryPaths: []string{"/entry.js"},
|
||||
options: config.Options{
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: true,
|
||||
},
|
||||
AbsOutputFile: "/out.js",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestLowerClassFieldNextNoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
@@ -1043,33 +990,6 @@ func TestLowerClassFieldNextNoBundle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerClassFieldStrict2020NoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
"/entry.ts": `
|
||||
class Foo {
|
||||
#foo = 123
|
||||
#bar
|
||||
foo = 123
|
||||
bar
|
||||
static #s_foo = 123
|
||||
static #s_bar
|
||||
static s_foo = 123
|
||||
static s_bar
|
||||
}
|
||||
`,
|
||||
},
|
||||
entryPaths: []string{"/entry.ts"},
|
||||
options: config.Options{
|
||||
UnsupportedJSFeatures: es(2020),
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: true,
|
||||
},
|
||||
AbsOutputFile: "/out.js",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerClassField2020NoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
@@ -1094,32 +1014,6 @@ func TestTSLowerClassField2020NoBundle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerClassPrivateFieldStrictNextNoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
"/entry.ts": `
|
||||
class Foo {
|
||||
#foo = 123
|
||||
#bar
|
||||
foo = 123
|
||||
bar
|
||||
static #s_foo = 123
|
||||
static #s_bar
|
||||
static s_foo = 123
|
||||
static s_bar
|
||||
}
|
||||
`,
|
||||
},
|
||||
entryPaths: []string{"/entry.ts"},
|
||||
options: config.Options{
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: true,
|
||||
},
|
||||
AbsOutputFile: "/out.js",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerClassPrivateFieldNextNoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
@@ -1185,6 +1079,48 @@ func TestLowerClassFieldStrictTsconfigJson2020(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerClassFieldStrictTsconfigJson2020(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
"/entry.js": `
|
||||
import loose from './loose'
|
||||
import strict from './strict'
|
||||
console.log(loose, strict)
|
||||
`,
|
||||
"/loose/index.ts": `
|
||||
export default class {
|
||||
foo
|
||||
}
|
||||
`,
|
||||
"/loose/tsconfig.json": `
|
||||
{
|
||||
"compilerOptions": {
|
||||
"useDefineForClassFields": false
|
||||
}
|
||||
}
|
||||
`,
|
||||
"/strict/index.ts": `
|
||||
export default class {
|
||||
foo
|
||||
}
|
||||
`,
|
||||
"/strict/tsconfig.json": `
|
||||
{
|
||||
"compilerOptions": {
|
||||
"useDefineForClassFields": true
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
entryPaths: []string{"/entry.js"},
|
||||
options: config.Options{
|
||||
Mode: config.ModeBundle,
|
||||
UnsupportedJSFeatures: es(2020),
|
||||
AbsOutputFile: "/out.js",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestTSLowerObjectRest2017NoBundle(t *testing.T) {
|
||||
lower_suite.expectBundled(t, bundled{
|
||||
files: map[string]string{
|
||||
|
||||
@@ -141,41 +141,6 @@ export {
|
||||
TestLowerClassField2020NoBundle
|
||||
---------- /out.js ----------
|
||||
var _foo, _bar, _s_foo, _s_bar;
|
||||
class Foo {
|
||||
constructor() {
|
||||
_foo.set(this, 123);
|
||||
_bar.set(this, void 0);
|
||||
this.foo = 123;
|
||||
this.bar = void 0;
|
||||
}
|
||||
}
|
||||
_foo = new WeakMap();
|
||||
_bar = new WeakMap();
|
||||
_s_foo = new WeakMap();
|
||||
_s_bar = new WeakMap();
|
||||
_s_foo.set(Foo, 123);
|
||||
_s_bar.set(Foo, void 0);
|
||||
Foo.s_foo = 123;
|
||||
Foo.s_bar = void 0;
|
||||
|
||||
================================================================================
|
||||
TestLowerClassFieldNextNoBundle
|
||||
---------- /out.js ----------
|
||||
class Foo {
|
||||
#foo = 123;
|
||||
#bar;
|
||||
foo = 123;
|
||||
bar;
|
||||
static #s_foo = 123;
|
||||
static #s_bar;
|
||||
static s_foo = 123;
|
||||
static s_bar;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
TestLowerClassFieldStrict2020NoBundle
|
||||
---------- /out.js ----------
|
||||
var _foo, _bar, _s_foo, _s_bar;
|
||||
class Foo {
|
||||
constructor() {
|
||||
_foo.set(this, 123);
|
||||
@@ -194,7 +159,7 @@ __publicField(Foo, "s_foo", 123);
|
||||
__publicField(Foo, "s_bar");
|
||||
|
||||
================================================================================
|
||||
TestLowerClassFieldStrictNextNoBundle
|
||||
TestLowerClassFieldNextNoBundle
|
||||
---------- /out.js ----------
|
||||
class Foo {
|
||||
#foo = 123;
|
||||
@@ -213,7 +178,7 @@ TestLowerClassFieldStrictTsconfigJson2020
|
||||
// /loose/index.js
|
||||
class loose_default {
|
||||
constructor() {
|
||||
this.foo = void 0;
|
||||
__publicField(this, "foo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,25 +864,21 @@ _s_bar.set(Foo, void 0);
|
||||
Foo.s_foo = 123;
|
||||
|
||||
================================================================================
|
||||
TestTSLowerClassFieldStrict2020NoBundle
|
||||
TestTSLowerClassFieldStrictTsconfigJson2020
|
||||
---------- /out.js ----------
|
||||
var _foo, _bar, _s_foo, _s_bar;
|
||||
class Foo {
|
||||
// /loose/index.ts
|
||||
class loose_default {
|
||||
}
|
||||
|
||||
// /strict/index.ts
|
||||
class strict_default {
|
||||
constructor() {
|
||||
_foo.set(this, 123);
|
||||
_bar.set(this, void 0);
|
||||
__publicField(this, "foo", 123);
|
||||
__publicField(this, "bar");
|
||||
__publicField(this, "foo");
|
||||
}
|
||||
}
|
||||
_foo = new WeakMap();
|
||||
_bar = new WeakMap();
|
||||
_s_foo = new WeakMap();
|
||||
_s_bar = new WeakMap();
|
||||
_s_foo.set(Foo, 123);
|
||||
_s_bar.set(Foo, void 0);
|
||||
__publicField(Foo, "s_foo", 123);
|
||||
__publicField(Foo, "s_bar");
|
||||
|
||||
// /entry.js
|
||||
console.log(loose_default, strict_default);
|
||||
|
||||
================================================================================
|
||||
TestTSLowerClassPrivateFieldNextNoBundle
|
||||
@@ -934,20 +895,6 @@ class Foo {
|
||||
}
|
||||
Foo.s_foo = 123;
|
||||
|
||||
================================================================================
|
||||
TestTSLowerClassPrivateFieldStrictNextNoBundle
|
||||
---------- /out.js ----------
|
||||
class Foo {
|
||||
#foo = 123;
|
||||
#bar;
|
||||
foo = 123;
|
||||
bar;
|
||||
static #s_foo = 123;
|
||||
static #s_bar;
|
||||
static s_foo = 123;
|
||||
static s_bar;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
TestTSLowerObjectRest2017NoBundle
|
||||
---------- /out.js ----------
|
||||
|
||||
@@ -167,10 +167,10 @@ type Options struct {
|
||||
|
||||
OmitRuntimeForTests bool
|
||||
PreserveUnusedImportsTS bool
|
||||
UseDefineForClassFields bool
|
||||
AvoidTDZ bool
|
||||
ASCIIOnly bool
|
||||
|
||||
Strict StrictOptions
|
||||
Defines *ProcessedDefines
|
||||
TS TSOptions
|
||||
JSX JSXOptions
|
||||
|
||||
@@ -10173,6 +10173,11 @@ func Parse(log logger.Log, source logger.Source, options config.Options) (result
|
||||
options.JSX.Fragment = []string{"React", "Fragment"}
|
||||
}
|
||||
|
||||
// Non-TypeScript files get the real JavaScript class field behavior
|
||||
if !options.TS.Parse {
|
||||
options.UseDefineForClassFields = true
|
||||
}
|
||||
|
||||
p := newParser(log, source, js_lexer.NewLexer(log, source), &options)
|
||||
|
||||
// Consume a leading hashbang comment
|
||||
|
||||
@@ -1587,7 +1587,7 @@ func (p *parser) lowerClass(stmt js_ast.Stmt, expr js_ast.Expr) ([]js_ast.Stmt,
|
||||
private, _ := prop.Key.Data.(*js_ast.EPrivateIdentifier)
|
||||
mustLowerPrivate := private != nil && p.isPrivateUnsupported(private)
|
||||
shouldOmitFieldInitializer := p.TS.Parse && !prop.IsMethod && prop.Initializer == nil &&
|
||||
!p.Strict.ClassFields && !mustLowerPrivate
|
||||
!p.UseDefineForClassFields && !mustLowerPrivate
|
||||
|
||||
// Class fields must be lowered if the environment doesn't support them
|
||||
mustLowerField := !prop.IsMethod && (!prop.IsStatic && p.UnsupportedJSFeatures.Has(compat.ClassField) ||
|
||||
@@ -1677,7 +1677,7 @@ func (p *parser) lowerClass(stmt js_ast.Stmt, expr js_ast.Expr) ([]js_ast.Stmt,
|
||||
// TypeScript feature. Move their initializers from the class body to
|
||||
// either the constructor (instance fields) or after the class (static
|
||||
// fields).
|
||||
if !prop.IsMethod && (mustLowerField || (p.TS.Parse && !p.Strict.ClassFields && (!prop.IsStatic || private == nil))) {
|
||||
if !prop.IsMethod && (mustLowerField || (p.TS.Parse && !p.UseDefineForClassFields && (!prop.IsStatic || private == nil))) {
|
||||
// The TypeScript compiler doesn't follow the JavaScript spec for
|
||||
// uninitialized fields. They are supposed to be set to undefined but the
|
||||
// TypeScript compiler just omits them entirely.
|
||||
@@ -1731,7 +1731,7 @@ func (p *parser) lowerClass(stmt js_ast.Stmt, expr js_ast.Expr) ([]js_ast.Stmt,
|
||||
},
|
||||
}}
|
||||
p.recordUsage(ref)
|
||||
} else if private == nil && p.Strict.ClassFields {
|
||||
} else if private == nil && p.UseDefineForClassFields {
|
||||
if _, ok := init.Data.(*js_ast.EUndefined); ok {
|
||||
expr = p.callRuntime(loc, "__publicField", []js_ast.Expr{target, prop.Key})
|
||||
} else {
|
||||
|
||||
@@ -93,18 +93,6 @@ func expectPrintedTarget(t *testing.T, esVersion int, contents string, expected
|
||||
})
|
||||
}
|
||||
|
||||
func expectPrintedTargetStrict(t *testing.T, esVersion int, contents string, expected string) {
|
||||
t.Helper()
|
||||
expectPrintedCommon(t, contents, expected, config.Options{
|
||||
UnsupportedJSFeatures: compat.UnsupportedJSFeatures(map[compat.Engine][]int{
|
||||
compat.ES: {esVersion},
|
||||
}),
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func expectPrintedASCII(t *testing.T, contents string, expected string) {
|
||||
t.Helper()
|
||||
expectPrintedCommon(t, contents, expected, config.Options{
|
||||
@@ -2572,7 +2560,7 @@ func TestLowerFunctionArgumentScope(t *testing.T) {
|
||||
test("a()?.b", "((_a) => (_a = a()) == null ? void 0 : _a.b)()")
|
||||
test("a?.b?.()", "((_a) => (_a = a == null ? void 0 : a.b) == null ? void 0 : _a.call(a))()")
|
||||
test("a.b.c?.()", "((_a) => ((_b) => (_b = (_a = a.b).c) == null ? void 0 : _b.call(_a))())()")
|
||||
test("class { static a }", "((_a) => (_a = class {\n}, _a.a = void 0, _a))()")
|
||||
test("class { static a }", "((_a) => (_a = class {\n}, __publicField(_a, \"a\"), _a))()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2663,9 +2651,9 @@ func TestLowerClassSideEffectOrder(t *testing.T) {
|
||||
`, `var _a, _b, _c, _d, _e;
|
||||
class Foo {
|
||||
constructor() {
|
||||
this[_a] = void 0;
|
||||
this[_b] = 1;
|
||||
this[_e] = void 0;
|
||||
__publicField(this, _a);
|
||||
__publicField(this, _b, 1);
|
||||
__publicField(this, _e);
|
||||
}
|
||||
[a()]() {
|
||||
}
|
||||
@@ -2675,27 +2663,27 @@ class Foo {
|
||||
}
|
||||
}
|
||||
_e = h();
|
||||
Foo[_c] = void 0;
|
||||
Foo[_d] = 1;
|
||||
__publicField(Foo, _c);
|
||||
__publicField(Foo, _d, 1);
|
||||
`)
|
||||
}
|
||||
|
||||
func TestLowerClassInstance(t *testing.T) {
|
||||
expectPrintedTarget(t, 2015, "class Foo {}", "class Foo {\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { foo }", "class Foo {\n constructor() {\n this.foo = void 0;\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { foo = null }", "class Foo {\n constructor() {\n this.foo = null;\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { 123 }", "class Foo {\n constructor() {\n this[123] = void 0;\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { 123 = null }", "class Foo {\n constructor() {\n this[123] = null;\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { [foo] }", "var _a;\nclass Foo {\n constructor() {\n this[_a] = void 0;\n }\n}\n_a = foo;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { [foo] = null }", "var _a;\nclass Foo {\n constructor() {\n this[_a] = null;\n }\n}\n_a = foo;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { foo }", "class Foo {\n constructor() {\n __publicField(this, \"foo\");\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { foo = null }", "class Foo {\n constructor() {\n __publicField(this, \"foo\", null);\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { 123 }", "class Foo {\n constructor() {\n __publicField(this, 123);\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { 123 = null }", "class Foo {\n constructor() {\n __publicField(this, 123, null);\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { [foo] }", "var _a;\nclass Foo {\n constructor() {\n __publicField(this, _a);\n }\n}\n_a = foo;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { [foo] = null }", "var _a;\nclass Foo {\n constructor() {\n __publicField(this, _a, null);\n }\n}\n_a = foo;\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "(class {})", "(class {\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { foo })", "(class {\n constructor() {\n this.foo = void 0;\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { foo = null })", "(class {\n constructor() {\n this.foo = null;\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { 123 })", "(class {\n constructor() {\n this[123] = void 0;\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { 123 = null })", "(class {\n constructor() {\n this[123] = null;\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { [foo] })", "var _a, _b;\n_b = class {\n constructor() {\n this[_a] = void 0;\n }\n}, _a = foo, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { [foo] = null })", "var _a, _b;\n_b = class {\n constructor() {\n this[_a] = null;\n }\n}, _a = foo, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { foo })", "(class {\n constructor() {\n __publicField(this, \"foo\");\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { foo = null })", "(class {\n constructor() {\n __publicField(this, \"foo\", null);\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { 123 })", "(class {\n constructor() {\n __publicField(this, 123);\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { 123 = null })", "(class {\n constructor() {\n __publicField(this, 123, null);\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { [foo] })", "var _a, _b;\n_b = class {\n constructor() {\n __publicField(this, _a);\n }\n}, _a = foo, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { [foo] = null })", "var _a, _b;\n_b = class {\n constructor() {\n __publicField(this, _a, null);\n }\n}, _a = foo, _b;\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "class Foo extends Bar {}", `class Foo extends Bar {
|
||||
}
|
||||
@@ -2711,7 +2699,7 @@ func TestLowerClassInstance(t *testing.T) {
|
||||
expectPrintedTarget(t, 2015, "class Foo extends Bar { bar() {} foo }", `class Foo extends Bar {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.foo = void 0;
|
||||
__publicField(this, "foo");
|
||||
}
|
||||
bar() {
|
||||
}
|
||||
@@ -2720,7 +2708,7 @@ func TestLowerClassInstance(t *testing.T) {
|
||||
expectPrintedTarget(t, 2015, "class Foo extends Bar { bar() {} foo; constructor() { super() } }", `class Foo extends Bar {
|
||||
constructor() {
|
||||
super();
|
||||
this.foo = void 0;
|
||||
__publicField(this, "foo");
|
||||
}
|
||||
bar() {
|
||||
}
|
||||
@@ -2729,88 +2717,88 @@ func TestLowerClassInstance(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLowerClassStatic(t *testing.T) {
|
||||
expectPrintedTarget(t, 2015, "class Foo { static foo }", "class Foo {\n}\nFoo.foo = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static foo = null }", "class Foo {\n}\nFoo.foo = null;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static foo }", "class Foo {\n}\n__publicField(Foo, \"foo\");\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static foo = null }", "class Foo {\n}\n__publicField(Foo, \"foo\", null);\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static foo(a, b) {} }", "class Foo {\n static foo(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static get foo() {} }", "class Foo {\n static get foo() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static set foo(a) {} }", "class Foo {\n static set foo(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static 123 }", "class Foo {\n}\nFoo[123] = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static 123 = null }", "class Foo {\n}\nFoo[123] = null;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static 123 }", "class Foo {\n}\n__publicField(Foo, 123);\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static 123 = null }", "class Foo {\n}\n__publicField(Foo, 123, null);\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static 123(a, b) {} }", "class Foo {\n static 123(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static get 123() {} }", "class Foo {\n static get 123() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static set 123(a) {} }", "class Foo {\n static set 123(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static [foo] }", "var _a;\nclass Foo {\n}\n_a = foo;\nFoo[_a] = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static [foo] = null }", "var _a;\nclass Foo {\n}\n_a = foo;\nFoo[_a] = null;\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static [foo] }", "var _a;\nclass Foo {\n}\n_a = foo;\n__publicField(Foo, _a);\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static [foo] = null }", "var _a;\nclass Foo {\n}\n_a = foo;\n__publicField(Foo, _a, null);\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static [foo](a, b) {} }", "class Foo {\n static [foo](a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static get [foo]() {} }", "class Foo {\n static get [foo]() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "class Foo { static set [foo](a) {} }", "class Foo {\n static set [foo](a) {\n }\n}\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static foo }", "export default class Foo {\n}\nFoo.foo = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static foo = null }", "export default class Foo {\n}\nFoo.foo = null;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static foo }", "export default class Foo {\n}\n__publicField(Foo, \"foo\");\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static foo = null }", "export default class Foo {\n}\n__publicField(Foo, \"foo\", null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static foo(a, b) {} }", "export default class Foo {\n static foo(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static get foo() {} }", "export default class Foo {\n static get foo() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static set foo(a) {} }", "export default class Foo {\n static set foo(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static 123 }", "export default class Foo {\n}\nFoo[123] = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static 123 = null }", "export default class Foo {\n}\nFoo[123] = null;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static 123 }", "export default class Foo {\n}\n__publicField(Foo, 123);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static 123 = null }", "export default class Foo {\n}\n__publicField(Foo, 123, null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static 123(a, b) {} }", "export default class Foo {\n static 123(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static get 123() {} }", "export default class Foo {\n static get 123() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static set 123(a) {} }", "export default class Foo {\n static set 123(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static [foo] }", "var _a;\nexport default class Foo {\n}\n_a = foo;\nFoo[_a] = void 0;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static [foo] = null }", "var _a;\nexport default class Foo {\n}\n_a = foo;\nFoo[_a] = null;\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static [foo] }", "var _a;\nexport default class Foo {\n}\n_a = foo;\n__publicField(Foo, _a);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static [foo] = null }", "var _a;\nexport default class Foo {\n}\n_a = foo;\n__publicField(Foo, _a, null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static [foo](a, b) {} }", "export default class Foo {\n static [foo](a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static get [foo]() {} }", "export default class Foo {\n static get [foo]() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class Foo { static set [foo](a) {} }", "export default class Foo {\n static set [foo](a) {\n }\n}\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "export default class { static foo }",
|
||||
"export default class stdin_default {\n}\nstdin_default.foo = void 0;\n")
|
||||
"export default class stdin_default {\n}\n__publicField(stdin_default, \"foo\");\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static foo = null }",
|
||||
"export default class stdin_default {\n}\nstdin_default.foo = null;\n")
|
||||
"export default class stdin_default {\n}\n__publicField(stdin_default, \"foo\", null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static foo(a, b) {} }", "export default class {\n static foo(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static get foo() {} }", "export default class {\n static get foo() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static set foo(a) {} }", "export default class {\n static set foo(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static 123 }",
|
||||
"export default class stdin_default {\n}\nstdin_default[123] = void 0;\n")
|
||||
"export default class stdin_default {\n}\n__publicField(stdin_default, 123);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static 123 = null }",
|
||||
"export default class stdin_default {\n}\nstdin_default[123] = null;\n")
|
||||
"export default class stdin_default {\n}\n__publicField(stdin_default, 123, null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static 123(a, b) {} }", "export default class {\n static 123(a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static get 123() {} }", "export default class {\n static get 123() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static set 123(a) {} }", "export default class {\n static set 123(a) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static [foo] }",
|
||||
"var _a;\nexport default class stdin_default {\n}\n_a = foo;\nstdin_default[_a] = void 0;\n")
|
||||
"var _a;\nexport default class stdin_default {\n}\n_a = foo;\n__publicField(stdin_default, _a);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static [foo] = null }",
|
||||
"var _a;\nexport default class stdin_default {\n}\n_a = foo;\nstdin_default[_a] = null;\n")
|
||||
"var _a;\nexport default class stdin_default {\n}\n_a = foo;\n__publicField(stdin_default, _a, null);\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static [foo](a, b) {} }", "export default class {\n static [foo](a, b) {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static get [foo]() {} }", "export default class {\n static get [foo]() {\n }\n}\n")
|
||||
expectPrintedTarget(t, 2015, "export default class { static set [foo](a) {} }", "export default class {\n static set [foo](a) {\n }\n}\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static foo })", "var _a;\n_a = class {\n}, _a.foo = void 0, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static foo = null })", "var _a;\n_a = class {\n}, _a.foo = null, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static foo })", "var _a;\n_a = class {\n}, __publicField(_a, \"foo\"), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static foo = null })", "var _a;\n_a = class {\n}, __publicField(_a, \"foo\", null), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static foo(a, b) {} })", "(class Foo {\n static foo(a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static get foo() {} })", "(class Foo {\n static get foo() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static set foo(a) {} })", "(class Foo {\n static set foo(a) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static 123 })", "var _a;\n_a = class {\n}, _a[123] = void 0, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static 123 = null })", "var _a;\n_a = class {\n}, _a[123] = null, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static 123 })", "var _a;\n_a = class {\n}, __publicField(_a, 123), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static 123 = null })", "var _a;\n_a = class {\n}, __publicField(_a, 123, null), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static 123(a, b) {} })", "(class Foo {\n static 123(a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static get 123() {} })", "(class Foo {\n static get 123() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static set 123(a) {} })", "(class Foo {\n static set 123(a) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static [foo] })", "var _a, _b;\n_b = class {\n}, _a = foo, _b[_a] = void 0, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static [foo] = null })", "var _a, _b;\n_b = class {\n}, _a = foo, _b[_a] = null, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static [foo] })", "var _a, _b;\n_b = class {\n}, _a = foo, __publicField(_b, _a), _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static [foo] = null })", "var _a, _b;\n_b = class {\n}, _a = foo, __publicField(_b, _a, null), _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static [foo](a, b) {} })", "(class Foo {\n static [foo](a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static get [foo]() {} })", "(class Foo {\n static get [foo]() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class Foo { static set [foo](a) {} })", "(class Foo {\n static set [foo](a) {\n }\n});\n")
|
||||
|
||||
expectPrintedTarget(t, 2015, "(class { static foo })", "var _a;\n_a = class {\n}, _a.foo = void 0, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static foo = null })", "var _a;\n_a = class {\n}, _a.foo = null, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static foo })", "var _a;\n_a = class {\n}, __publicField(_a, \"foo\"), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static foo = null })", "var _a;\n_a = class {\n}, __publicField(_a, \"foo\", null), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static foo(a, b) {} })", "(class {\n static foo(a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static get foo() {} })", "(class {\n static get foo() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static set foo(a) {} })", "(class {\n static set foo(a) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static 123 })", "var _a;\n_a = class {\n}, _a[123] = void 0, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static 123 = null })", "var _a;\n_a = class {\n}, _a[123] = null, _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static 123 })", "var _a;\n_a = class {\n}, __publicField(_a, 123), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static 123 = null })", "var _a;\n_a = class {\n}, __publicField(_a, 123, null), _a;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static 123(a, b) {} })", "(class {\n static 123(a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static get 123() {} })", "(class {\n static get 123() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static set 123(a) {} })", "(class {\n static set 123(a) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static [foo] })", "var _a, _b;\n_b = class {\n}, _a = foo, _b[_a] = void 0, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static [foo] = null })", "var _a, _b;\n_b = class {\n}, _a = foo, _b[_a] = null, _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static [foo] })", "var _a, _b;\n_b = class {\n}, _a = foo, __publicField(_b, _a), _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static [foo] = null })", "var _a, _b;\n_b = class {\n}, _a = foo, __publicField(_b, _a, null), _b;\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static [foo](a, b) {} })", "(class {\n static [foo](a, b) {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static get [foo]() {} })", "(class {\n static get [foo]() {\n }\n});\n")
|
||||
expectPrintedTarget(t, 2015, "(class { static set [foo](a) {} })", "(class {\n static set [foo](a) {\n }\n});\n")
|
||||
@@ -2828,7 +2816,7 @@ func TestLowerClassStatic(t *testing.T) {
|
||||
}
|
||||
`, `var _a;
|
||||
let Bar = (_a = class {
|
||||
}, _a.foo = 123, _a.bar = _a.foo, _a);
|
||||
}, __publicField(_a, "foo", 123), __publicField(_a, "bar", _a.foo), _a);
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ type ResolveResult struct {
|
||||
IgnoreIfUnused bool
|
||||
|
||||
// If true, the class field transform should use Object.defineProperty().
|
||||
StrictClassFields bool
|
||||
UseDefineForClassFieldsTS bool
|
||||
|
||||
// If true, unused imports are retained in TypeScript code. This matches the
|
||||
// behavior of the "importsNotUsedAsValues" field in "tsconfig.json" when the
|
||||
@@ -222,7 +222,7 @@ func (r *resolver) finalizeResolve(result ResolveResult) *ResolveResult {
|
||||
if path == &result.PathPair.Primary && dirInfo.tsConfigJSON != nil {
|
||||
result.JSXFactory = dirInfo.tsConfigJSON.JSXFactory
|
||||
result.JSXFragment = dirInfo.tsConfigJSON.JSXFragmentFactory
|
||||
result.StrictClassFields = dirInfo.tsConfigJSON.UseDefineForClassFields
|
||||
result.UseDefineForClassFieldsTS = dirInfo.tsConfigJSON.UseDefineForClassFields
|
||||
result.PreserveUnusedImportsTS = dirInfo.tsConfigJSON.PreserveImportsNotUsedAsValues
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ let mustBeStringOrObject = (value: string | Object | undefined): string | null =
|
||||
let mustBeStringOrArray = (value: string | string[] | undefined): string | null =>
|
||||
typeof value === 'string' || Array.isArray(value) ? null : 'a string or an array';
|
||||
|
||||
let mustBeBooleanOrArray = (value: boolean | string[] | undefined): string | null =>
|
||||
typeof value === 'boolean' || Array.isArray(value) ? null : 'a boolean or an array';
|
||||
|
||||
type OptionKeys = { [key: string]: boolean };
|
||||
|
||||
function getFlag<T, K extends keyof T>(object: T, keys: OptionKeys, key: K, mustBeFn: (value: T[K]) => string | null): T[K] | undefined {
|
||||
@@ -72,7 +69,6 @@ function pushCommonFlags(flags: string[], options: CommonOptions, keys: OptionKe
|
||||
let target = getFlag(options, keys, 'target', mustBeStringOrArray);
|
||||
let format = getFlag(options, keys, 'format', mustBeString);
|
||||
let globalName = getFlag(options, keys, 'globalName', mustBeString);
|
||||
let strict = getFlag(options, keys, 'strict', mustBeBooleanOrArray);
|
||||
let minify = getFlag(options, keys, 'minify', mustBeBoolean);
|
||||
let minifySyntax = getFlag(options, keys, 'minifySyntax', mustBeBoolean);
|
||||
let minifyWhitespace = getFlag(options, keys, 'minifyWhitespace', mustBeBoolean);
|
||||
@@ -90,8 +86,6 @@ function pushCommonFlags(flags: string[], options: CommonOptions, keys: OptionKe
|
||||
}
|
||||
if (format) flags.push(`--format=${format}`);
|
||||
if (globalName) flags.push(`--global-name=${globalName}`);
|
||||
if (strict === true) flags.push(`--strict`);
|
||||
else if (strict) for (let key of strict) flags.push(`--strict:${key}`);
|
||||
|
||||
if (minify) flags.push('--minify');
|
||||
if (minifySyntax) flags.push('--minify-syntax');
|
||||
|
||||
@@ -2,7 +2,6 @@ export type Platform = 'browser' | 'node';
|
||||
export type Format = 'iife' | 'cjs' | 'esm';
|
||||
export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary';
|
||||
export type LogLevel = 'info' | 'warning' | 'error' | 'silent';
|
||||
export type Strict = 'class-fields';
|
||||
export type Charset = 'ascii' | 'utf8';
|
||||
|
||||
interface CommonOptions {
|
||||
@@ -10,7 +9,6 @@ interface CommonOptions {
|
||||
format?: Format;
|
||||
globalName?: string;
|
||||
target?: string | string[];
|
||||
strict?: boolean | Strict[];
|
||||
|
||||
minify?: boolean;
|
||||
minifyWhitespace?: boolean;
|
||||
|
||||
@@ -177,10 +177,6 @@ const (
|
||||
LogLevelError
|
||||
)
|
||||
|
||||
type StrictOptions struct {
|
||||
ClassFields bool
|
||||
}
|
||||
|
||||
type Charset uint8
|
||||
|
||||
const (
|
||||
@@ -200,7 +196,6 @@ type BuildOptions struct {
|
||||
Sourcemap SourceMap
|
||||
Target Target
|
||||
Engines []Engine
|
||||
Strict StrictOptions
|
||||
|
||||
MinifyWhitespace bool
|
||||
MinifyIdentifiers bool
|
||||
@@ -272,7 +267,6 @@ type TransformOptions struct {
|
||||
Format Format
|
||||
GlobalName string
|
||||
Engines []Engine
|
||||
Strict StrictOptions
|
||||
|
||||
MinifyWhitespace bool
|
||||
MinifyIdentifiers bool
|
||||
|
||||
@@ -90,12 +90,6 @@ func validateLogLevel(value LogLevel) logger.LogLevel {
|
||||
}
|
||||
}
|
||||
|
||||
func validateStrict(value StrictOptions) config.StrictOptions {
|
||||
return config.StrictOptions{
|
||||
ClassFields: value.ClassFields,
|
||||
}
|
||||
}
|
||||
|
||||
func validateASCIIOnly(value Charset) bool {
|
||||
switch value {
|
||||
case CharsetDefault, CharsetASCII:
|
||||
@@ -419,9 +413,6 @@ func buildImpl(buildOpts BuildOptions) BuildResult {
|
||||
options := config.Options{
|
||||
UnsupportedJSFeatures: jsFeatures,
|
||||
UnsupportedCSSFeatures: cssFeatures,
|
||||
Strict: config.StrictOptions{
|
||||
ClassFields: buildOpts.Strict.ClassFields,
|
||||
},
|
||||
JSX: config.JSXOptions{
|
||||
Factory: validateJSX(log, buildOpts.JSXFactory, "factory"),
|
||||
Fragment: validateJSX(log, buildOpts.JSXFragment, "fragment"),
|
||||
@@ -619,13 +610,11 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult
|
||||
|
||||
// Settings from the user come first
|
||||
preserveUnusedImportsTS := false
|
||||
useDefineForClassFieldsTS := false
|
||||
jsx := config.JSXOptions{
|
||||
Factory: validateJSX(log, transformOpts.JSXFactory, "factory"),
|
||||
Fragment: validateJSX(log, transformOpts.JSXFragment, "fragment"),
|
||||
}
|
||||
strict := config.StrictOptions{
|
||||
ClassFields: transformOpts.Strict.ClassFields,
|
||||
}
|
||||
|
||||
// Settings from "tsconfig.json" override those
|
||||
if transformOpts.TsconfigRaw != "" {
|
||||
@@ -642,7 +631,7 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult
|
||||
jsx.Fragment = result.JSXFragmentFactory
|
||||
}
|
||||
if result.UseDefineForClassFields {
|
||||
strict.ClassFields = true
|
||||
useDefineForClassFieldsTS = true
|
||||
}
|
||||
if result.PreserveImportsNotUsedAsValues {
|
||||
preserveUnusedImportsTS = true
|
||||
@@ -655,7 +644,6 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult
|
||||
options := config.Options{
|
||||
UnsupportedJSFeatures: jsFeatures,
|
||||
UnsupportedCSSFeatures: cssFeatures,
|
||||
Strict: strict,
|
||||
JSX: jsx,
|
||||
Defines: validateDefines(log, transformOpts.Define, transformOpts.Pure),
|
||||
SourceMap: validateSourceMap(transformOpts.Sourcemap),
|
||||
@@ -667,6 +655,7 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult
|
||||
ASCIIOnly: validateASCIIOnly(transformOpts.Charset),
|
||||
AbsOutputFile: transformOpts.Sourcefile + "-out",
|
||||
AvoidTDZ: transformOpts.AvoidTDZ,
|
||||
UseDefineForClassFields: useDefineForClassFieldsTS,
|
||||
PreserveUnusedImportsTS: preserveUnusedImportsTS,
|
||||
Stdin: &config.StdinInfo{
|
||||
Loader: validateLoader(transformOpts.Loader),
|
||||
|
||||
@@ -233,31 +233,6 @@ func parseOptionsImpl(osArgs []string, buildOpts *api.BuildOptions, transformOpt
|
||||
}
|
||||
buildOpts.OutExtensions[value[:equals]] = value[equals+1:]
|
||||
|
||||
case arg == "--strict":
|
||||
value := api.StrictOptions{
|
||||
ClassFields: true,
|
||||
}
|
||||
if buildOpts != nil {
|
||||
buildOpts.Strict = value
|
||||
} else {
|
||||
transformOpts.Strict = value
|
||||
}
|
||||
|
||||
case strings.HasPrefix(arg, "--strict:"):
|
||||
var value *api.StrictOptions
|
||||
if buildOpts != nil {
|
||||
value = &buildOpts.Strict
|
||||
} else {
|
||||
value = &transformOpts.Strict
|
||||
}
|
||||
name := arg[len("--strict:"):]
|
||||
switch name {
|
||||
case "class-fields":
|
||||
value.ClassFields = true
|
||||
default:
|
||||
return fmt.Errorf("Invalid strict value: %q (valid: class-fields)", name)
|
||||
}
|
||||
|
||||
case strings.HasPrefix(arg, "--platform=") && buildOpts != nil:
|
||||
value := arg[len("--platform="):]
|
||||
switch value {
|
||||
|
||||
@@ -1131,17 +1131,6 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let called = false
|
||||
class Foo {
|
||||
foo
|
||||
set foo(x) { called = true }
|
||||
}
|
||||
new Foo()
|
||||
if (!called) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
'in.js': `
|
||||
let setterCalls = 0
|
||||
class Foo {
|
||||
@@ -1152,7 +1141,7 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
if (setterCalls !== 0 || !foo.hasOwnProperty('key') || foo.key !== void 0) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let setterCalls = 0
|
||||
class Foo {
|
||||
@@ -1163,7 +1152,7 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
if (setterCalls !== 0 || !foo.hasOwnProperty('key') || foo.key !== 123) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let toStringCalls = 0
|
||||
let setterCalls = 0
|
||||
@@ -1178,7 +1167,7 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
if (setterCalls !== 0 || toStringCalls !== 1 || !foo.hasOwnProperty('key') || foo.key !== void 0) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let toStringCalls = 0
|
||||
let setterCalls = 0
|
||||
@@ -1193,7 +1182,7 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
if (setterCalls !== 0 || toStringCalls !== 1 || !foo.hasOwnProperty('key') || foo.key !== 123) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let key = Symbol('key')
|
||||
let setterCalls = 0
|
||||
@@ -1205,7 +1194,7 @@ in.js:24:30: warning: Writing to getter-only property "#getter" will throw
|
||||
if (setterCalls !== 0 || !foo.hasOwnProperty(key) || foo[key] !== void 0) throw 'fail'
|
||||
`,
|
||||
}),
|
||||
test(['in.js', '--outfile=node.js', '--target=es6', '--strict'], {
|
||||
test(['in.js', '--outfile=node.js', '--target=es6'], {
|
||||
'in.js': `
|
||||
let key = Symbol('key')
|
||||
let setterCalls = 0
|
||||
|
||||
@@ -195,11 +195,6 @@
|
||||
</select>
|
||||
</label>
|
||||
<br>
|
||||
<label for="strict">
|
||||
<input id="strict" type="checkbox">
|
||||
Strict
|
||||
</label>
|
||||
|
||||
<label for="ascii">
|
||||
<input id="ascii" type="checkbox">
|
||||
ASCII
|
||||
@@ -225,7 +220,6 @@
|
||||
const minifySyntax = document.querySelector('#minify-syntax')
|
||||
const minifyIdents = document.querySelector('#minify-idents')
|
||||
const minifySpaces = document.querySelector('#minify-spaces')
|
||||
const strict = document.querySelector('#strict')
|
||||
const ascii = document.querySelector('#ascii')
|
||||
let runIfIdle
|
||||
|
||||
@@ -265,7 +259,6 @@
|
||||
persistChecked(minifySyntax, 'minifySyntax')
|
||||
persistChecked(minifyIdents, 'minifyIdents')
|
||||
persistChecked(minifySpaces, 'minifySpaces')
|
||||
persistChecked(strict, 'strict')
|
||||
persistChecked(ascii, 'ascii')
|
||||
|
||||
try {
|
||||
@@ -305,7 +298,6 @@
|
||||
minifySyntax: minifySyntax.checked,
|
||||
minifyIdentifiers: minifyIdents.checked,
|
||||
minifyWhitespace: minifySpaces.checked,
|
||||
strict: strict.checked,
|
||||
charset: ascii.checked ? 'ascii' : 'utf8',
|
||||
}).then(({ code, warnings }) => {
|
||||
let html = messagesToHTML(addKindToMessages(warnings, 'warning'))
|
||||
|
||||
Reference in New Issue
Block a user