Skip to content

Commit

Permalink
feat(typescript): support BigInt (#5546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Nov 27, 2018
1 parent 3a5bbf5 commit 05ad885
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -66,8 +66,8 @@
"resolve": "1.5.0",
"semver": "5.4.1",
"string-width": "2.1.1",
"typescript": "3.0.1",
"typescript-estree": "1.0.0",
"typescript": "3.2.0-rc",
"typescript-estree": "6.0.0-rc.1",
"unicode-regex": "2.0.0",
"unified": "6.1.6",
"vnopts": "1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/language-js/parser-typescript.js
Expand Up @@ -43,7 +43,7 @@ function tryParseTypeScript(text, jsx) {
tokens: true,
comment: true,
useJSXTextNode: true,
ecmaFeatures: { jsx },
jsx,
// Override logger function with noop,
// to avoid unsupported version errors being logged
loggerFn: () => {}
Expand Down
25 changes: 12 additions & 13 deletions src/language-js/printer-estree.js
Expand Up @@ -1573,7 +1573,15 @@ function printPathNoParens(path, options, print, args) {
case "NumericLiteral": // Babel 6 Literal split
return printNumber(n.extra.raw);
case "BigIntLiteral":
return concat([printNumber(n.extra.rawValue), "n"]);
return concat([
printNumber(
n.extra
? n.extra.rawValue
: // TypeScript
n.value
),
"n"
]);
case "BooleanLiteral": // Babel 6 Literal split
case "StringLiteral": // Babel 6 Literal split
case "Literal": {
Expand Down Expand Up @@ -2098,7 +2106,6 @@ function printPathNoParens(path, options, print, args) {
);
}
case "JSXFragment":
case "TSJsxFragment":
case "JSXElement": {
const elem = comments.printComments(
path,
Expand Down Expand Up @@ -2204,14 +2211,11 @@ function printPathNoParens(path, options, print, args) {
case "JSXClosingElement":
return concat(["</", path.call(print, "name"), ">"]);
case "JSXOpeningFragment":
case "JSXClosingFragment":
case "TSJsxOpeningFragment":
case "TSJsxClosingFragment": {
case "JSXClosingFragment": {
const hasComment = n.comments && n.comments.length;
const hasOwnLineComment =
hasComment && !n.comments.every(handleComments.isBlockComment);
const isOpeningFragment =
n.type === "JSXOpeningFragment" || n.type === "TSJsxOpeningFragment";
const isOpeningFragment = n.type === "JSXOpeningFragment";
return concat([
isOpeningFragment ? "<" : "</",
indent(
Expand Down Expand Up @@ -4961,11 +4965,7 @@ function isCallOrOptionalCallExpression(node) {
}

function isJSXNode(node) {
return (
node.type === "JSXElement" ||
node.type === "JSXFragment" ||
node.type === "TSJsxFragment"
);
return node.type === "JSXElement" || node.type === "JSXFragment";
}

function isEmptyJSXElement(node) {
Expand Down Expand Up @@ -5507,7 +5507,6 @@ function maybeWrapJSXElementInParens(path, elem) {
JSXElement: true,
JSXExpressionContainer: true,
JSXFragment: true,
TSJsxFragment: true,
ExpressionStatement: true,
CallExpression: true,
OptionalCallExpression: true,
Expand Down
2 changes: 1 addition & 1 deletion tests/big-int/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -2,7 +2,7 @@

exports[`literal.js 1`] = `
====================================options=====================================
parsers: ["babylon"]
parsers: ["babylon", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
Expand Down
2 changes: 1 addition & 1 deletion tests/big-int/jsfmt.spec.js
@@ -1 +1 @@
run_spec(__dirname, ["babylon"]);
run_spec(__dirname, ["babylon", "typescript"]);
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -5698,16 +5698,16 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript-estree@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-1.0.0.tgz#6266f31108d2f12594cb996d0e16d938e3cb83cd"
typescript-estree@6.0.0-rc.1:
version "6.0.0-rc.1"
resolved "https://registry.yarnpkg.com/typescript-estree/-/typescript-estree-6.0.0-rc.1.tgz#2bc3d89d206ebdfa04cdebd9acf03aed9fff8860"
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"

typescript@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"
typescript@3.2.0-rc:
version "3.2.0-rc"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.0-rc.tgz#7c3816f1c761b096f4f1712382e872f4da8f263e"

ua-parser-js@^0.7.9:
version "0.7.17"
Expand Down

0 comments on commit 05ad885

Please sign in to comment.