Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(typescript-estree): if the template literal is tagged and the text has an invalid escape,cooked will benull#11355

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
nayounsang wants to merge5 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromnayounsang:tag-cook
Draft
Show file tree
Hide file tree
Changes fromall 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

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 1 addition & 1 deletionpackages/ast-spec/src/special/TemplateElement/spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ export interface TemplateElement extends BaseNode {
type:AST_NODE_TYPES.TemplateElement;
tail:boolean;
value:{
cooked:string;
cooked:string|null;
raw:string;
};
}
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

75 changes: 60 additions & 15 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,6 +90,7 @@ function isEntityNameExpression(
}

export class Converter {
#isInTaggedTemplate = false;
private allowPattern = false;
private readonly ast: ts.SourceFile;
private readonly esTreeNodeToTSNodeMap = new WeakMap();
Expand DownExpand Up@@ -401,6 +402,38 @@ export class Converter {
}
}

#isValidEscape(arg: string): boolean {
const unicode = /\\u([0-9a-fA-F]{4})/g;
const unicodeBracket = /\\u\{([0-9a-fA-F]+)\}/g; // supports ES6+
const hex = /\\x([0-9a-fA-F]{2})/g;
const validShort = /\\[nrtbfv0\\'"]/g;

const allEscapes =
/\\(u\{[^}]*\}|u[0-9a-fA-F]{0,4}|x[0-9a-fA-F]{0,2}|[^ux])/g;

let match: RegExpExecArray | null;
while ((match = allEscapes.exec(arg)) != null) {
const escape = match[0];

if (
unicode.test(escape) ||
(unicodeBracket.test(escape) &&
(() => {
const cp = parseInt(escape.match(unicodeBracket)![1], 16);
return cp <= 0x10ffff;
})()) ||
hex.test(escape) ||
validShort.test(escape)
) {
continue;
}

return false;
}

return true;
}

#throwError(node: number | ts.Node, message: string): asserts node is never {
let start;
let end;
Expand DownExpand Up@@ -1889,7 +1922,10 @@ export class Converter {
type: AST_NODE_TYPES.TemplateElement,
tail: true,
value: {
cooked: node.text,
cooked:
this.#isValidEscape(node.text) && this.#isInTaggedTemplate
? node.text
: null,
raw: this.ast.text.slice(
node.getStart(this.ast) + 1,
node.end - 1,
Expand DownExpand Up@@ -1917,19 +1953,25 @@ export class Converter {
return result;
}

case SyntaxKind.TaggedTemplateExpression:
return this.createNode<TSESTree.TaggedTemplateExpression>(node, {
type: AST_NODE_TYPES.TaggedTemplateExpression,
quasi: this.convertChild(node.template),
tag: this.convertChild(node.tag),
typeArguments:
node.typeArguments &&
this.convertTypeArgumentsToTypeParameterInstantiation(
node.typeArguments,
node,
),
});

case SyntaxKind.TaggedTemplateExpression: {
this.#isInTaggedTemplate = true;
const result = this.createNode<TSESTree.TaggedTemplateExpression>(
node,
{
type: AST_NODE_TYPES.TaggedTemplateExpression,
quasi: this.convertChild(node.template),
tag: this.convertChild(node.tag),
typeArguments:
node.typeArguments &&
this.convertTypeArgumentsToTypeParameterInstantiation(
node.typeArguments,
node,
),
},
);
this.#isInTaggedTemplate = false;
return result;
}
case SyntaxKind.TemplateHead:
case SyntaxKind.TemplateMiddle:
case SyntaxKind.TemplateTail: {
Expand All@@ -1938,7 +1980,10 @@ export class Converter {
type: AST_NODE_TYPES.TemplateElement,
tail,
value: {
cooked: node.text,
cooked:
this.#isValidEscape(node.text) && this.#isInTaggedTemplate
? node.text
: null,
raw: this.ast.text.slice(
node.getStart(this.ast) + 1,
node.end - (tail ? 1 : 2),
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp