Skip to content
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

ts.createPrinter().printFile の結果に Unicode 文字を含む場合は unescape する #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion src/lib/converters/classApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getExportStatement,
getImportStatement,
lifecycleNameMap,
containUnicodeChar,
} from "../helper";
import { convertOptions } from "./options/optionsConverter";

Expand Down Expand Up @@ -141,7 +142,11 @@ export const convertClass = (
sourceFile.flags
);
const printer = ts.createPrinter();
return printer.printFile(newSrc);
const content = printer.printFile(newSrc);

return containUnicodeChar(content)
? unescape(content.replace(/\\u/g, "%u"))
: content;
};

const parseClassNode = (
Expand Down
12 changes: 10 additions & 2 deletions src/lib/converters/optionsApiConverter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import ts from "typescript";
import { getExportStatement, getImportStatement } from "../helper";
import {
getExportStatement,
getImportStatement,
containUnicodeChar,
} from "../helper";
import { convertOptions } from "./options/optionsConverter";

export const convertOptionsApi = (sourceFile: ts.SourceFile) => {
Expand All @@ -20,5 +24,9 @@ export const convertOptionsApi = (sourceFile: ts.SourceFile) => {
sourceFile.flags
);
const printer = ts.createPrinter();
return printer.printFile(newSrc);
const content = printer.printFile(newSrc);

return containUnicodeChar(content)
? unescape(content.replace(/\\u/g, "%u"))
: content;
};
4 changes: 4 additions & 0 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@ export const getSetupStatements = (setupProps: ConvertedExpression[]) => {
)
.flat();
};

export const containUnicodeChar = (str: string) => {
return /\\u.{4}/gi.test(str);
};