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

feat(typescript): support BigInt #5546

Merged
merged 3 commits into from Nov 27, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1571,7 +1571,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 @@ -2096,7 +2104,6 @@ function printPathNoParens(path, options, print, args) {
);
}
case "JSXFragment":
case "TSJsxFragment":
case "JSXElement": {
const elem = comments.printComments(
path,
Expand Down Expand Up @@ -2202,14 +2209,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 @@ -4977,11 +4981,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 @@ -5523,7 +5523,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