Skip to content

module: remove extra padding from ts errors #57704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion deps/amaro/dist/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export function isSwcError(error) {
return error.code !== void 0;
}
export function wrapAndReThrowSwcError(error) {
const errorHints = `${error.filename}:${error.startLine}${error.snippet}`;
const errorHints = `${error.filename}:${error.startLine}
${error.snippet}
`;
switch (error.code) {
case "UnsupportedSyntax": {
const unsupportedSyntaxError = new Error(error.message);
Expand Down
6 changes: 3 additions & 3 deletions deps/amaro/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/amaro/dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"강동윤 <[email protected]>"
],
"description": "wasm module for swc",
"version": "1.11.12",
"version": "1.11.15",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion deps/amaro/dist/strip-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
import { fileURLToPath } from "node:url";
import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
Expand All @@ -10,7 +11,8 @@ export async function load(url, context, nextLoad) {
format: "module"
});
const { code } = transformSync(source.toString(), {
mode: "strip-only"
mode: "strip-only",
filename: fileURLToPath(url)
});
return {
format: format.replace("-typescript", ""),
Expand Down
3 changes: 2 additions & 1 deletion deps/amaro/dist/transform-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
import { fileURLToPath } from "node:url";
import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
Expand All @@ -12,7 +13,7 @@ export async function load(url, context, nextLoad) {
const { code, map } = transformSync(source.toString(), {
mode: "transform",
sourceMap: true,
filename: url
filename: fileURLToPath(url)
});
let output = code;
if (map) {
Expand Down
2 changes: 1 addition & 1 deletion deps/amaro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amaro",
"version": "0.5.0",
"version": "0.5.1",
"description": "Node.js TypeScript wrapper",
"license": "MIT",
"type": "commonjs",
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function parseTypeScript(source, options) {
* @returns {Error} the decorated error
*/
function decorateErrorWithSnippet(error, amaroError) {
const errorHints = `${amaroError.filename}:${amaroError.startLine}${amaroError.snippet}`;
error.stack = `${errorHints}${error.stack}`;
const errorHints = `${amaroError.filename}:${amaroError.startLine}\n${amaroError.snippet}`;
error.stack = `${errorHints}\n${error.stack}`;
return error;
}

Expand Down
2 changes: 1 addition & 1 deletion src/amaro_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Refer to tools/dep_updaters/update-amaro.sh
#ifndef SRC_AMARO_VERSION_H_
#define SRC_AMARO_VERSION_H_
#define AMARO_VERSION "0.5.0"
#define AMARO_VERSION "0.5.1"
#endif // SRC_AMARO_VERSION_H_
10 changes: 4 additions & 6 deletions test/es-module/test-typescript-eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,10 @@ test('the error message should not contain extra padding', async () => {
strictEqual(result.stdout, '');
// Windows uses \r\n as line endings
const lines = result.stderr.replace(/\r\n/g, '\n').split('\n');
// The extra padding at the end should not be present
strictEqual(lines[0], '[eval]:1 ');
// The extra padding at the beginning should not be present
strictEqual(lines[2], ' declare module F { export type x = number }');
strictEqual(lines[3], ' ^^^^^^^^');
strictEqual(lines[5], 'SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]:' +
strictEqual(lines[0], '[eval]:1');
strictEqual(lines[1], 'declare module F { export type x = number }');
strictEqual(lines[2], ' ^^^^^^^^');
strictEqual(lines[4], 'SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]:' +
' `module` keyword is not supported. Use `namespace` instead.');
strictEqual(result.code, 1);
});
Loading