test(es): Add tests for fixed issues (#3875)

**Description:**

Adds tests for fixed issues.
This commit modifies one type because the previous type makes transform flaky.

**BREAKING CHANGE:**

To preserve order, the type `swc::Paths` is now `IndexMap` instead of `HashMap`.
This commit is contained in:
Donny/강동윤 2022-03-06 11:27:08 +09:00 committed by GitHub
parent d524cc3c5b
commit 8d3c9d39f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 168 additions and 1 deletions

View File

@ -1054,7 +1054,7 @@ impl Merge for JscExperimental {
}
/// `paths` section of `tsconfig.json`.
pub type Paths = AHashMap<String, Vec<String>>;
pub type Paths = IndexMap<String, Vec<String>, ahash::RandomState>;
pub(crate) type CompiledPaths = Vec<(String, Vec<String>)>;
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -1558,6 +1558,19 @@ impl Merge for JscConfig {
}
}
impl<K, V, S> Merge for IndexMap<K, V, S>
where
K: Clone + Eq + std::hash::Hash,
V: Clone,
S: Clone + BuildHasher,
{
fn merge(&mut self, from: &Self) {
if self.is_empty() {
*self = (*from).clone();
}
}
}
impl<K, V, S> Merge for HashMap<K, V, S>
where
K: Clone + Eq + std::hash::Hash,

View File

@ -0,0 +1,21 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"transform": null,
"target": "es5",
"loose": false,
"externalHelpers": false
}
}

View File

@ -0,0 +1 @@
class X { st\u0061tic y() { } }

View File

@ -0,0 +1,14 @@
import * as swcHelpers from "@swc/helpers";
var X = /*#__PURE__*/ function() {
"use strict";
function X() {
swcHelpers.classCallCheck(this, X);
}
swcHelpers.createClass(X, null, [
{
key: "y",
value: function y() {}
}
]);
return X;
}();

View File

@ -0,0 +1,26 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2019",
"baseUrl": "./src",
"paths": {
"core/*": [
"core/*"
],
"utils/*": [
"utils/*"
],
"core": [
"core"
],
"utils": [
"utils"
]
}
},
"module": {
"type": "commonjs"
}
}

View File

@ -0,0 +1,2 @@
import * as utilFile from 'core/utils/utilFile'
import * as utils from 'utils'

View File

@ -0,0 +1 @@
export function test() {}

View File

@ -0,0 +1,6 @@
import 'core/module/moduleFile'
import 'core/utils'
import 'core/utilFile'
import 'utils'
console.log('SUCCESS');

View File

@ -0,0 +1,3 @@
import { test } from 'core/utils/utilFile'
test();
export function utilFn() {}

View File

@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@ -0,0 +1 @@
"use strict";

View File

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.test = test;
function test() {}

View File

@ -0,0 +1,6 @@
"use strict";
require("./core/module/moduleFile");
require("./core/utils/index");
require("./core/utilFile");
require("./utils");
console.log('SUCCESS');

View File

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.utilFn = utilFn;
var _utilFile = require("../core/utils/utilFile");
(0, _utilFile).test();
function utilFn() {}

View File

@ -0,0 +1,3 @@
{
"sourceMaps": true
}

View File

@ -0,0 +1 @@
if(true){var h=Symbol.for;}

View File

@ -0,0 +1,3 @@
if (true) {
var h = Symbol.for;
}

View File

@ -0,0 +1,15 @@
{
"mappings": "AAAA,EAAE,EAAC,IAAI,EAAC,CAAC;IAAA,GAAG,CAACA,CAAC,GAACC,MAAM,CAACC,GAAG;AAAC,CAAC",
"names": [
"h",
"Symbol",
"for"
],
"sources": [
"../../input/index.js"
],
"sourcesContent": [
"if(true){var h=Symbol.for;}"
],
"version": 3
}

View File

@ -0,0 +1 @@
const [...rest,] = a

View File

@ -0,0 +1,6 @@
error: Expected ']', got ','
--> $DIR/tests/typescript-errors/issue-3676/input.ts:1:15
|
1 | const [...rest,] = a
| ^

View File

@ -0,0 +1,14 @@
/** @jsx h */
/** @jsxFrag Fragment */
import { h, jsx, Fragment} from 'https://deno.land/x/sift@0.4.3/mod.ts';
export const pageLayout = ()=>jsx(
<>
< !doctype html >
<html lang='en-US' charSet='UTF-8'>
<Head/>
<Body/>
</html>,
</>
);

View File

@ -0,0 +1,12 @@
error: Unexpected token `!`. Expected an identifier, void, yield, null, await, break, a string literal, a numeric literal, true, false, `, -, import, this, typeof, {, [, (
--> $DIR/tests/typescript-errors/issue-3712/input.ts:8:6
|
8 | < !doctype html >
| ^
error: Expression expected
--> $DIR/tests/typescript-errors/issue-3712/input.ts:7:4
|
7 | <>
| ^