Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: Replace removed API with public flags (fixes #498) #505

Merged
merged 3 commits into from
Jul 26, 2018
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
npm-debug.log
_test.js
.DS_Store
.vscode
.vscode
yarn.lock
6 changes: 3 additions & 3 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ module.exports = function convert(config) {
],
loc: nodeUtils.getLocFor(firstTypeParameter.pos - 1, greaterThanToken.end, ast),
params: typeParameters.map(typeParameter => {
const name = nodeUtils.unescapeIdentifier(typeParameter.name.text);
const name = typeParameter.name.text;

const constraint = typeParameter.constraint
? convert({ node: typeParameter.constraint, parent: typeParameter, ast, additionalOptions })
Expand Down Expand Up @@ -473,7 +473,7 @@ module.exports = function convert(config) {
case SyntaxKind.Identifier:
Object.assign(result, {
type: AST_NODE_TYPES.Identifier,
name: nodeUtils.unescapeIdentifier(node.text)
name: node.text
});
break;

Expand Down Expand Up @@ -1748,7 +1748,7 @@ module.exports = function convert(config) {
raw: ast.text.slice(result.range[0], result.range[1])
});
if (parent.name && parent.name === node) {
result.value = nodeUtils.unescapeIdentifier(node.text);
result.value = node.text;
} else {
result.value = nodeUtils.unescapeStringLiteralText(node.text);
}
Expand Down
52 changes: 7 additions & 45 deletions lib/node-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,6 @@ function findFirstMatchingChild(node, sourceFile, predicate) {
return undefined;
}

/**
* Returns true if the given TSNode is a let variable declaration
* @param {TSNode} node The TSNode
* @returns {boolean} whether or not the given node is a let variable declaration
*/
function isLet(node) {
/**
* TODO: Remove dependency on private TypeScript method
*/
return ts.isLet(node);
}

/**
* Returns true if the given TSNode is a const variable declaration
* @param {TSNode} node The TSNode
* @returns {boolean} whether or not the given node is a const variable declaration
*/
function isConst(node) {
/**
* TODO: Remove dependency on private TypeScript method
*/
return ts.isConst(node);
}

//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -179,7 +155,6 @@ module.exports = {
findFirstMatchingAncestor,
findAncestorOfKind,
hasJSXAncestor,
unescapeIdentifier,
unescapeStringLiteralText,
isComputedProperty,
isOptional,
Expand Down Expand Up @@ -366,24 +341,20 @@ function isTypeKeyword(kind) {
* @returns {string} declaration kind
*/
function getDeclarationKind(node) {
let varDeclarationKind;
switch (node.kind) {
case SyntaxKind.TypeAliasDeclaration:
varDeclarationKind = "type";
break;
return "type";
case SyntaxKind.VariableDeclarationList:
if (isLet(node)) {
varDeclarationKind = "let";
} else if (isConst(node)) {
varDeclarationKind = "const";
} else {
varDeclarationKind = "var";
if (node.flags & ts.NodeFlags.Let) {
return "let";
}
break;
if (node.flags & ts.NodeFlags.Const) {
return "const";
}
return "var";
default:
throw "Unable to determine declaration kind.";
}
return varDeclarationKind;
}

/**
Expand Down Expand Up @@ -502,15 +473,6 @@ function hasJSXAncestor(node) {
return !!findFirstMatchingAncestor(node, isJSXToken);
}

/**
* Remove extra underscore from escaped identifier text content.
* @param {string} identifier The escaped identifier text.
* @returns {string} The unescaped identifier text.
*/
function unescapeIdentifier(identifier) {
return ts.unescapeIdentifier(identifier);
}

/**
* Unescape the text content of string literals, e.g. & -> &
* @param {string} text The escaped string literal text.
Expand Down