Skip to content

Commit

Permalink
fix(es/parser): Fix context of dynamic import type (#9852)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9802
  • Loading branch information
kdy1 authored Jan 8, 2025
1 parent 71982c5 commit caa7f37
Show file tree
Hide file tree
Showing 6 changed files with 1,689 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/pretty-news-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_parser: patch
---

fix(es/parser): Fix context of dynamic import type
41 changes: 41 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9802/input/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
import typia from "typia";
export const parse = (() => {
const __is = (input: any): input is number => "number" === typeof input;
let errors: any;
let _report: any;
const __validate = (input: any): import("typia").IValidation<number> => {
if (false === __is(input)) {
errors = [];
_report = (__typia_transform__validateReport._validateReport as any)(
errors
);
((input: any, _path: string, _exceptionable: boolean = true) =>
"number" === typeof input ||
_report(true, {
path: _path + "",
expected: "number",
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
data: input,
} as any;
};
return (
input: string
): import("typia").IValidation<import("typia").Primitive<number>> =>
__validate(JSON.parse(input)) as any;
})();
38 changes: 38 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9802/output/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
export var parse = function() {
var __is = function(input) {
return "number" === typeof input;
};
var errors;
var _report;
var __validate = function(input) {
if (false === __is(input)) {
errors = [];
_report = __typia_transform__validateReport._validateReport(errors);
(function(input, _path) {
var _exceptionable = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
return "number" === typeof input || _report(true, {
path: _path + "",
expected: "number",
value: input
});
})(input, "$input", true);
var success = 0 === errors.length;
return success ? {
success: success,
data: input
} : {
success: success,
errors: errors,
data: input
};
}
return {
success: true,
data: input
};
};
return function(input) {
return __validate(JSON.parse(input));
};
}();
7 changes: 6 additions & 1 deletion crates/swc_ecma_parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ impl<I: Tokens> Parser<I> {
};

let type_args = if is!(self, '<') {
self.parse_ts_type_args().map(Some)?
self.with_ctx(Context {
should_not_lex_lt_or_gt_as_type: false,
..self.ctx()
})
.parse_ts_type_args()
.map(Some)?
} else {
None
};
Expand Down
41 changes: 41 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/issue-9802/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
import typia from "typia";
export const parse = (() => {
const __is = (input: any): input is number => "number" === typeof input;
let errors: any;
let _report: any;
const __validate = (input: any): import("typia").IValidation<number> => {
if (false === __is(input)) {
errors = [];
_report = (__typia_transform__validateReport._validateReport as any)(
errors
);
((input: any, _path: string, _exceptionable: boolean = true) =>
"number" === typeof input ||
_report(true, {
path: _path + "",
expected: "number",
value: input,
}))(input, "$input", true);
const success = 0 === errors.length;
return success
? {
success,
data: input,
}
: ({
success,
errors,
data: input,
} as any);
}
return {
success: true,
data: input,
} as any;
};
return (
input: string
): import("typia").IValidation<import("typia").Primitive<number>> =>
__validate(JSON.parse(input)) as any;
})();
Loading

0 comments on commit caa7f37

Please sign in to comment.