-
Notifications
You must be signed in to change notification settings - Fork 680
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
Storten Number and Infinity constants #340
Open
FarSeeing
wants to merge
7
commits into
mishoo:master
Choose a base branch
from
FarSeeing:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4da85c
Shorten Number constants: Infinity and NaN
84f74c4
Also correctly shortcut -Infinity
d902ac5
Added unit tests
ac9cecd
Whitespace fix
4f1fa12
Shortcut Number.NaN to 0/0 instead of NaN
4786404
Small fixes on NaN
925cb6f
Shorten -Infinity to 1/-0 instead of -1/0
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,37 @@ function ast_squeeze_more(ast) { | |
} | ||
} | ||
}, | ||
|
||
// shorten Number constants: | ||
// Number.POSITIVE_INFINITY to 1/0, Number.NEGATIVE_INFINITY to -1/0, Number.NaN to NaN | ||
"dot": function(expr, name) { | ||
if (expr[0] == "name" && expr[1] == "Number" && !scope.has("Number")) { | ||
if (name == "POSITIVE_INFINITY") { | ||
return [ "binary", "/", [ "num", 1 ], [ "num", 0 ] ]; | ||
} | ||
if (name == "NEGATIVE_INFINITY") { | ||
return [ "binary", "/", [ "num", -1 ], [ "num", 0 ] ]; | ||
} | ||
if (name == "NaN" && !scope.has("NaN")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to check whether |
||
return [ "binary", "/", [ "num", 0 ], [ "num", 0 ] ]; | ||
} | ||
} | ||
}, | ||
|
||
// shorten Infinity constant to 1/0 | ||
"name": function(name) { | ||
if (name == "Infinity" && !scope.has("Infinity")) { | ||
return [ "binary", "/", [ "num", 1 ], [ "num", 0 ] ]; | ||
} | ||
}, | ||
|
||
// shorten -Infinity constant to -1/0 | ||
"unary-prefix": function(op, expr) { | ||
if (op == "-" && expr[0] == "name" && expr[1] == "Infinity" && !scope.has("Infinity")) { | ||
return [ "binary", "/", [ "num", -1 ], [ "num", 0 ] ]; | ||
} | ||
}, | ||
|
||
"call": function(expr, args) { | ||
if (expr[0] == "dot" && expr[1][0] == "string" && args.length == 1 | ||
&& (args[0][1] > 0 && expr[2] == "substring" || expr[2] == "substr")) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function test(){var a={};return a}1/0,-1/0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1/0,-1/0,0/0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(function(){var a={};return a.POSITIVE_INFINITY||a.NEGATIVE_INFINITY||a.NaN})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Infinity; | ||
-Infinity; | ||
|
||
function test() | ||
{ | ||
var Infinity = {}; | ||
return Infinity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Number.POSITIVE_INFINITY; | ||
Number.NEGATIVE_INFINITY; | ||
Number.NaN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(function(){ | ||
var Number = {}; | ||
return Number.POSITIVE_INFINITY || Number.NEGATIVE_INFINITY || Number.NaN; | ||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.NaN
to0/0