Skip to content

Commit f1d7de3

Browse files
texastolandJamesHenry
authored andcommitted
Chore: Replace removed API with public flags (fixes eslint#498) (eslint#505)
1 parent 21fec5a commit f1d7de3

File tree

3 files changed

+12
-49
lines changed

3 files changed

+12
-49
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules
44
npm-debug.log
55
_test.js
66
.DS_Store
7-
.vscode
7+
.vscode
8+
yarn.lock

lib/convert.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ module.exports = function convert(config) {
189189
],
190190
loc: nodeUtils.getLocFor(firstTypeParameter.pos - 1, greaterThanToken.end, ast),
191191
params: typeParameters.map(typeParameter => {
192-
const name = nodeUtils.unescapeIdentifier(typeParameter.name.text);
192+
const name = typeParameter.name.text;
193193

194194
const constraint = typeParameter.constraint
195195
? convert({ node: typeParameter.constraint, parent: typeParameter, ast, additionalOptions })
@@ -473,7 +473,7 @@ module.exports = function convert(config) {
473473
case SyntaxKind.Identifier:
474474
Object.assign(result, {
475475
type: AST_NODE_TYPES.Identifier,
476-
name: nodeUtils.unescapeIdentifier(node.text)
476+
name: node.text
477477
});
478478
break;
479479

@@ -1748,7 +1748,7 @@ module.exports = function convert(config) {
17481748
raw: ast.text.slice(result.range[0], result.range[1])
17491749
});
17501750
if (parent.name && parent.name === node) {
1751-
result.value = nodeUtils.unescapeIdentifier(node.text);
1751+
result.value = node.text;
17521752
} else {
17531753
result.value = nodeUtils.unescapeStringLiteralText(node.text);
17541754
}

lib/node-utils.js

+7-45
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,6 @@ function findFirstMatchingChild(node, sourceFile, predicate) {
125125
return undefined;
126126
}
127127

128-
/**
129-
* Returns true if the given TSNode is a let variable declaration
130-
* @param {TSNode} node The TSNode
131-
* @returns {boolean} whether or not the given node is a let variable declaration
132-
*/
133-
function isLet(node) {
134-
/**
135-
* TODO: Remove dependency on private TypeScript method
136-
*/
137-
return ts.isLet(node);
138-
}
139-
140-
/**
141-
* Returns true if the given TSNode is a const variable declaration
142-
* @param {TSNode} node The TSNode
143-
* @returns {boolean} whether or not the given node is a const variable declaration
144-
*/
145-
function isConst(node) {
146-
/**
147-
* TODO: Remove dependency on private TypeScript method
148-
*/
149-
return ts.isConst(node);
150-
}
151-
152128
//------------------------------------------------------------------------------
153129
// Public
154130
//------------------------------------------------------------------------------
@@ -179,7 +155,6 @@ module.exports = {
179155
findFirstMatchingAncestor,
180156
findAncestorOfKind,
181157
hasJSXAncestor,
182-
unescapeIdentifier,
183158
unescapeStringLiteralText,
184159
isComputedProperty,
185160
isOptional,
@@ -366,24 +341,20 @@ function isTypeKeyword(kind) {
366341
* @returns {string} declaration kind
367342
*/
368343
function getDeclarationKind(node) {
369-
let varDeclarationKind;
370344
switch (node.kind) {
371345
case SyntaxKind.TypeAliasDeclaration:
372-
varDeclarationKind = "type";
373-
break;
346+
return "type";
374347
case SyntaxKind.VariableDeclarationList:
375-
if (isLet(node)) {
376-
varDeclarationKind = "let";
377-
} else if (isConst(node)) {
378-
varDeclarationKind = "const";
379-
} else {
380-
varDeclarationKind = "var";
348+
if (node.flags & ts.NodeFlags.Let) {
349+
return "let";
381350
}
382-
break;
351+
if (node.flags & ts.NodeFlags.Const) {
352+
return "const";
353+
}
354+
return "var";
383355
default:
384356
throw "Unable to determine declaration kind.";
385357
}
386-
return varDeclarationKind;
387358
}
388359

389360
/**
@@ -502,15 +473,6 @@ function hasJSXAncestor(node) {
502473
return !!findFirstMatchingAncestor(node, isJSXToken);
503474
}
504475

505-
/**
506-
* Remove extra underscore from escaped identifier text content.
507-
* @param {string} identifier The escaped identifier text.
508-
* @returns {string} The unescaped identifier text.
509-
*/
510-
function unescapeIdentifier(identifier) {
511-
return ts.unescapeIdentifier(identifier);
512-
}
513-
514476
/**
515477
* Unescape the text content of string literals, e.g. & -> &
516478
* @param {string} text The escaped string literal text.

0 commit comments

Comments
 (0)