Skip to content

Commit e38343b

Browse files
remove unused babel plugins, reduce size a bit
1 parent 8821776 commit e38343b

File tree

8 files changed

+180
-172
lines changed

8 files changed

+180
-172
lines changed

.babelrc

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
[
55
"@babel/preset-env",
66
{
7-
"targets": {
8-
"browsers": ["last 2 versions"]
9-
},
7+
"targets": { "browsers": "defaults, not ie 11", "node": true },
108
"modules": false,
119
"useBuiltIns": false,
1210
"loose": true
1311
}
1412
]
1513
],
16-
"plugins": [
17-
"babel-plugin-dev-expression",
18-
"@babel/plugin-transform-modules-commonjs",
19-
"@babel/plugin-proposal-object-rest-spread",
20-
"@babel/plugin-proposal-class-properties"
21-
]
14+
"plugins": ["@babel/plugin-transform-modules-commonjs"]
2215
}

config/rollup-umd-min.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@ config.plugins = [
2525
[
2626
'@babel/preset-env',
2727
{
28-
targets: {
29-
browsers: ['last 2 versions'],
30-
},
28+
targets: { browsers: 'defaults, not ie 11' },
3129
modules: false,
3230
useBuiltIns: false,
3331
loose: true,
3432
},
3533
],
3634
],
37-
plugins: [
38-
'babel-plugin-dev-expression',
39-
'@babel/plugin-proposal-object-rest-spread',
40-
'@babel/plugin-proposal-class-properties',
41-
],
4235
}),
4336

4437
cjs({

config/rollup.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,13 @@ export default {
2323
[
2424
'@babel/preset-env',
2525
{
26-
targets: {
27-
// browsers: ['last 2 versions'],
28-
node: true,
29-
},
26+
targets: { browsers: 'defaults, not ie 11', node: true },
3027
modules: false,
3128
useBuiltIns: false,
3229
loose: true,
3330
},
3431
],
3532
],
36-
plugins: [
37-
'@babel/plugin-proposal-object-rest-spread',
38-
'@babel/plugin-proposal-class-properties',
39-
],
4033
}),
4134

4235
cjs({

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"devDependencies": {
1818
"@babel/cli": "^7.6.3",
1919
"@babel/core": "^7.6.3",
20-
"@babel/plugin-proposal-class-properties": "^7.5.5",
21-
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
22-
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
20+
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
2321
"@babel/preset-env": "^7.6.3",
2422
"@babel/preset-typescript": "^7.6.0",
2523
"@babel/register": "^7.6.2",
@@ -29,7 +27,6 @@
2927
"@typescript-eslint/eslint-plugin": "^4.8.2",
3028
"@typescript-eslint/parser": "^4.8.2",
3129
"babel-eslint": "^10.0.3",
32-
"babel-plugin-dev-expression": "^0.2.2",
3330
"eslint": "^7.14.0",
3431
"eslint-config-prettier": "^6.15.0",
3532
"eslint-plugin-import": "^2.22.1",

src/error.ts

+7-21
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,23 @@ export type Failure = {
2323

2424
export class StructError extends TypeError {
2525
value: any
26-
key: string | number | undefined
27-
type: string
28-
refinement: string | undefined
29-
path: Array<number | string>
30-
branch: Array<any>
26+
key!: string | number | undefined
27+
type!: string
28+
refinement!: string | undefined
29+
path!: Array<number | string>
30+
branch!: Array<any>
3131
failures: () => Array<Failure>;
3232
[x: string]: any
3333

3434
constructor(failure: Failure, moreFailures: IterableIterator<Failure>) {
35-
const {
36-
path,
37-
value,
38-
key,
39-
type,
40-
message,
41-
refinement,
42-
branch,
43-
...rest
44-
} = failure
35+
const { message, ...rest } = failure
36+
const { path } = failure
4537
let failures: Array<Failure> | undefined
4638
const msg =
4739
path.length === 0 ? message : `At path: ${path.join('.')} -- ${message}`
4840
super(msg)
4941
Object.assign(this, rest)
5042
this.name = this.constructor.name
51-
this.value = value
52-
this.key = key
53-
this.type = type
54-
this.refinement = refinement
55-
this.path = path
56-
this.branch = branch
5743
this.failures = (): Array<Failure> => {
5844
if (!failures) {
5945
failures = [failure, ...moreFailures]

src/struct.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@ export class Struct<T = unknown, S = unknown> {
2323
validator?: Struct<T, S>['validator']
2424
refiner?: Struct<T, S>['refiner']
2525
}) {
26-
const {
27-
type,
28-
schema,
29-
coercer = (value: unknown) => value,
30-
validator = () => [],
31-
refiner = () => [],
32-
} = props
33-
this.type = type
34-
this.schema = schema
35-
this.coercer = coercer
36-
this.validator = validator
37-
this.refiner = refiner
26+
this.type = props.type
27+
this.schema = props.schema
28+
this.coercer = props.coercer || ((value: unknown) => value)
29+
this.validator = props.validator || (() => [])
30+
this.refiner = props.refiner || (() => [])
3831
}
3932

4033
/**

src/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ export function isPlainObject(value: unknown): value is { [key: string]: any } {
1818
* Return a value as a printable string.
1919
*/
2020

21-
export function print(value: any, ticks?: string): string {
22-
const string = typeof value === 'string' ? JSON.stringify(value) : `${value}`
23-
return ticks ? `${ticks}${string}${ticks}` : string
21+
export function print(value: any): string {
22+
return typeof value === 'string' ? JSON.stringify(value) : `${value}`
2423
}
2524

2625
/**

0 commit comments

Comments
 (0)