zloirock / core-js Goto Github PK
View Code? Open in Web Editor NEWStandard Library
License: MIT License
Standard Library
License: MIT License
Unlike native promises are intended to eventually and unlike promise libraries like when, bluebird and rsvp and like older libraries - the Promise shim does not perform any form of unhandled rejection tracking.
This means that a promise that failed but does not have a catch
handler attached will perform a silent failure creating debuggability issues since your code would fail but you would not know where.
ES6 does not include any done
like method to explicitly terminate a chain because modern promise libraries as well as native promises now can in practice detect unhandled rejections pretty well.
Please consider adding unhandled rejection tracking to the promises shim so the promises will no longer silently fail by default.
Can anyone please confirm that they have React working with Core-js (e.g. core-js/client/shim) on IE8?
In our case it fails with "undefined is null or not an object" on the first if-statement in:
function createChainableTypeChecker(validate) {
function checkType(isRequired, props, propName, componentName, location) {
componentName = componentName || ANONYMOUS;
if (props[propName] == null) {
var locationName = ReactPropTypeLocationNames[location];
if (isRequired) {
return new Error(
("Required " + locationName + " `" + propName + "` was not specified in ")+
("`" + componentName + "`.")
);
}
} else {
return validate(props, propName, componentName, location);
}
}
> Symbol() instanceof Symbol
true
should be false
.
just noticed core-js
missing fetch
polyfill
subjectively best existing implemetation https://github.com/github/fetch
I've been trying to get babel working with a node package that ultimate requires the package xregexp. I've narrowed the problem down so it's simple to reproduce.
If I create a simple script and install these two packages:
> npm install babel
> npm install xregexp
var xregexp = require('xregexp');
require("babel/register");
var xregexp = require('xregexp');
I don't follow what the shim is trying to do, so I don't know how to attempt to fix it.
Here is the stack trace for the error that happens:
D:\TEMP\babel-issue1\node_modules\babel\node_modules\core-js\shim.js:1150
? pattern.source : pattern, flags);
^
SyntaxError: Invalid flags supplied to RegExp constructor 'gy'
at RegExp (native)
at new RegExp (D:\TEMP\babel-issue1\node_modules\babel\node_modules\core-js\shim.js:1150:28)
at copy (D:\TEMP\babel-issue1\node_modules\xregexp\xregexp-all.js:154:29)
at addToken.on (D:\TEMP\babel-issue1\node_modules\xregexp\xregexp-all.js:393:30)
at D:\TEMP\babel-issue1\node_modules\xregexp\xregexp-all.js:1138:5
at Object.<anonymous> (D:\TEMP\babel-issue1\node_modules\xregexp\xregexp-all.js:1267:2)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) [as .js] (D:\TEMP\babel-issue1\node_modules\babel\lib\babel\api\register\node.js:113:7)
at Module.load (module.js:355:32)
Consider overriding Number
constructor to test for cases like 0o7351...
and 0b010101...
so that those are getting converted with corresponding radix.
Possible implementation:
var oldNumber = Number;
Number = function(obj) {
if (typeof obj === 'string') {
var res;
if (res = obj.match(/^0o([0-7]+)$/i)) {
obj = parseInt(res[1], 8);
} else if (res = obj.match(/^0b([0-1]+)$/i)) {
obj = parseInt(res[1], 2);
}
}
return oldNumber.apply(this, arguments);
};
I've tried to inject it on my own and send PR, but core-js internals are somewhat complicated so I didn't find a way to override obvious way to override global Number
with own implementation.
This project looks amazing 😄 After skimming the document, it wasn't clear to me what the difference is between the browser "default" build and the "shim only" build. Does the default include the dictionary extensions but shim only includes standards shims? Can you confirm?
I reported this on the babel project and @sebmck said I should report it over here.
Using babel/core.js with projects that rely on requestAnimationFrame or setImmediate I see "Invalid Calling Object" errors when viewing in IE 11 on Windows 7.
I believe that when you alias setImmediate in IE you have to first bind the function to a calling object.
Here is the specific issue I hit with the Flummox project:
References:
caolan/async#299
browserify/browserify#237
https://msdn.microsoft.com/library/gg622930(v=vs.85).aspx
Specific code for the Flummox issue is a Flummox action class that utilizes async/await. Babel is being run with stage=0.
'use strict';
import {Actions} from 'flummox';
import request from '../util/HttpRequest';
export default class MessageActions extends Actions {
async getAllMessages() {
try {
let response = await request.get('/api/messages').exec();
return response.body;
} catch (err) {
console.log(err);
}
}
async getMessage(id) {
try {
let response = await request.get(`/api/messages/${id}`).exec();
return response.body;
} catch (err) {
console.log(err);
}
}
}
After transpilation by webpack, when I load the page in the dev server, the error "Invalid Calling Object" occurs in the file es6.promise.js at the line:
if(isReject || chain.length)asap(function(){
The error only occurs in IE, works fine on mac/win firefox/safari/chrome.
Similar issues with requestAnimationFrame
facebookarchive/fixed-data-table#15
jquense/react-widgets#91
Hi,
A reroll of babel/babel#427
Basically, this line is the offending one: https://github.com/zloirock/core-js/blob/master/index.js#L2084
See the angular link for more info: https://docs.angularjs.org/api/ng/directive/ngCsp
I'm not sure how this should be handled. Maybe a global variable could be used as an option setting?
Core.js replaces native WeakMap implementation. Tested in Node.js v0.11.14 with latest 6to5, which includes core.js as a polyfill for ES6 features.
Unless you preform some sort of sanity checks when npm installs core-js
, or have a good reason to ship the test out with every copy of core-js
, would you accept a PR to add an .npmignore
file?
That way, npm doesn't install 1.1MB of tests into node_modules for every library that uses core-js
.
(Additionally, it shrinks 6to5
from ~20MB on my machine.)
BTW, great job on this library. It's amazing!
This is related to babel/babel#545 and was previously filed as babel/babel#884
I had this code (working in Firefox without Babel):
for (let contentGroupEl of xmlDocument.getElementsByTagName('contentGroups')) {
...
}
Where xmlDocument is defined as follows:
var xmlDocument = (new DOMParser).parseFromString(content, "application/xhtml+xml");
The above loop iterates over a HTMLCollection.
Babel + Browser Polyfill from babel-core npm package (v4.4.6) generates the following JS, which throws an exception in Chrome:
for (var _iterator = xmlDocument.getElementsByTagName("contentGroups")[Symbol.iterator](), _step; !(_step = _iterator.next()).done; ) {
var contentGroupEl = _step.value;
}
TypeError: undefined is not a function: since xmlDocument.getElementsByTagName("contentGroups")[Symbol.iterator]
equals undefined
.
Is is possible to extend HTMLCollection with the iterator methods as well?
My current workaround looks like this:
for (let contentGroupEl of[].slice.call(xmlDocument.getElementsByTagName('contentGroups'))) {
...
Simply extending the HTMLCollection prototype does not seem to work. This code has no effect on the HTMLCollection instances.
if (!HTMLCollection.prototype[Symbol.iterator]) {
HTMLCollection.prototype[Symbol.iterator] = [][Symbol.iterator]
}
It would be nice if methods such as console.log
weren't overriden in Chrome because this breaks "jump to source" in DevTools.
[00:42:29] TypeError: boolean is not a function
at Function.isPlainObject (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/node_modules/globule/node_modules/lodash/dist/lodash.js:1652:64)
at Object.globule.find (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/node_modules/globule/lib/globule.js:64:19)
at Gaze.add (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:174:19)
at new Gaze (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:74:10)
at gaze (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:86:10)
at Object.module.exports [as watch] (/home/kaylee/projects/manic/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/index.js:12:17)
at Gulp.watch (/home/kaylee/projects/manic/node_modules/gulp/index.js:35:16)
at Gulp.<anonymous> (/home/kaylee/projects/manic/gulpfile.babel.js:85:10)
at module.exports (/home/kaylee/projects/manic/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/home/kaylee/projects/manic/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
Issue History:
babel/babel#489
gulpjs/glob-watcher#15
lodash/lodash#981
Like Array.turn
.
It would be very cool.
I am having an issue with babeljs, see my gist https://gist.github.com/Globegitter/ee46154b9a1b7506af19 as well as explaining comment: babel/babel#1134 (comment)
And according to babel/babel#1134 (comment) this seems to be an issue with core-js itself.
To summarise the issue:
I am using babeljs to transpile my tests but not in the actual app-code itself. The app-code in question uses promises without a library, so should only work in node 0.12.x as well as io.js 1.x. But for some reason the tests are still passing on node 0.10.x.
And it seems the issue lies in core-js and the globals it pollutes. Anyway, let me know if you need any more clarification about the test-example.
JsLint reports error when using version from https://raw.githubusercontent.com/zloirock/core-js/master/client/core.js
[error] W:\core\js\zloirock\core.js:16: Comma warnings can be turned off with 'laxcomma'.
[error] , OBJECT = 'Object'
[error] ^
[error] W:\core\js\zloirock\core.js:14: Bad line breaking before ','.
[error] var global = returnThis()
[error] ^
[error] W:\core\js\zloirock\core.js:16: Bad line breaking before ','.
[error] , OBJECT = 'Object'
[error] ^
[error] W:\core\js\zloirock\core.js:42: Bad line breaking before ','.
[error] , Function = global[FUNCTION]
[error] ^
[error] W:\core\js\zloirock\core.js:43: Bad line breaking before ','.
[error] , Object = global[OBJECT]
[error] ^
This may be not the only one errors detected, I suggest running jsint on a build after fixing this.
Math.cbrt(-x)
should be equal to -Math.cbrt(x)
HI!
It would be awesome if you would maintain a submission to http://www.webjars.org/
If project maintainer does this, updates are released with a lightning speed =)
Спасибо за хорошую работу!
Would it be possible to expose a library API that works with the Function Bind Syntax?
I mean, an API similar to the current library API, but which uses the this
binding instead of the first argument for instance methods. For instance, instead of:
var core = require('core-js/library');
core.String.repeat('*', 10);
Do something like:
var core = require('core-js/library');
'*'::core.String.prototype.repeat(10);
// transpiles to:
core.String.prototype.repeat.call('*', 10);
Needless to say, this would be an excellent way to avoid polluting the built-in prototypes while maintaining composability.
> console
{ log: [Function],
info: [Function],
warn: [Function],
error: [Function],
dir: [Function],
time: [Function],
timeEnd: [Function],
trace: [Function],
assert: [Function],
Console: [Function: Console] }
> require("core-js/library");
{ Object: {},
Number: {},
Math: {},
String: {},
Array: {},
RegExp: {},
_: {},
Function: {},
Date: {},
locale: [Function],
addLocale: [Function: addLocale] }
> console
ReferenceError: console is not defined
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
Are you going to add fetch
?
https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
I hope it's not too much trouble to ask to use unix line endings? At Facebook, we are checking in core-js via babeljs and this is causing trouble with our source control system.
Is it possible, or would it be relatively easy, to support doing this:
var core = require("core-js");
core.Array.from("abcdefg");
Without also polluting Array.prototype.from
etc?
Object.observe
has already landed in Chrome and Opera, and is part of the ES7 proposal. There is a polyfill that already supports it. Are there any plans for this feature to land in core-js?
Hi,
I have got some reports regarding to older Android devices throwing on this particular line (807):
TypeError: Result of expression 'fn' [undefined] is not a function
This is the bundled core-js version in latest babel (ref: babel/babel#1109). I'm not sure if this has been fixed in later releases of core-js, I can't reproduce it myself but we received several complaints from Android users since we switched to babel and core-js for polyfills.
Any ideas?
As per the proposal at https://github.com/DavidBruant/Map-Set.prototype.toJSON, the toJSON method for Map/Set objects would be a useful addition to core-js.
Array.prototype.slice.call(document.body.childNodes) //=> JSObject Expected
This code:
Line 275 in 275afdd
[11:40:02.146] TypeError: inst[FOR_EACH] is not a function
isWeak || inst[FOR_EACH](function(val, key){
$ node
> require("core-js/shim")
TypeError: Cannot set property console of [object Object] which has only a getter
at $define (/Users/sebastian/Projects/6to5/6to5/node_modules/core-js/shim.js:516:31)
at /Users/sebastian/Projects/6to5/6to5/node_modules/core-js/shim.js:1501:3
at /Users/sebastian/Projects/6to5/6to5/node_modules/core-js/shim.js:1522:2
at Object.<anonymous> (/Users/sebastian/Projects/6to5/6to5/node_modules/core-js/shim.js:1523:2)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
See discussions here: grigio/meteor-babel#5
(!) I am not using core-js and do not want to do this. So you can ignore this issue.
-0
key should be converted to +0
: var map = new Map();
map.set(-0, -0);
map.forEach(function (value, key) {
if (1 / key !== Infinity) {
throw new Error(1 / key); // during iteration note
}
});
if (map.get(-0) !== map.get(+0)) {
throw new Error();
}
var map = new Map();
map.set("0", 9);
map.set("1", 9);
map.set("2", 9);
map.set("3", 9);
var s = "";
map.forEach(function (value, key) {
s += key;
if (key === "2") {
map.delete("2");
map.delete("3");
map.delete("1");
map.set("4", 9);
}
});
if (s !== "0124") {
throw new Error(s);
}
The behavior or parsing a date or date+time string to a Date
object (using the new Date(string)
constructor, or Date.parse(string)
function) is changed in ES6. AFAIK, this isn't currently handled by the core-js ES6 polyfills. Should it be? My understanding is that this is a dependency for libraries such as Babel. (originally filed as babel/babel#1418)
Behavior
If the time zone offset is absent, the date-time is interpreted as a local time.
The value of an absent time zone offset is "Z".
To get ES6 behavior out of ES5, the string would need to be mutated to be interpreted in local time. The polyfill would have to be careful only to do this for the specific use cases affected.
ES6 | ES5 |
---|---|
new Date("2014-12-31") |
new Date("2014/12/31") |
new Date("2014-12-31T01:23:45") |
new Date("2014/12/31 01:23:45") |
new Date("2014-12-31T01:23:45Z") |
no change |
new Date("2014-12-31T01:23:45-05:00") |
no change |
Note, the hyphens are replaced with slashes, but still kept in year/month/day order to prevent internationalization ambiguities. Also note the T
removed. Also note that ECMAScript only defines the ISO8601/RFC3339 format, leaving everything else implementation specific. It just happens that all major implementations support the formats I showed.
Seems to be missing. As described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString
I'm using 6to5's polyfill—which includes "core-js/shim"
—and in IE 8 I'm getting the error "Object expected" referencing this line of code:
...
if(!isNative(Symbol)){
Symbol = function(description){
assert(!(this instanceof Symbol), SYMBOL + ' is not a ' + CONSTRUCTOR);
var tag = uid(description)
, sym = set(create(Symbol[PROTOTYPE]), TAG, tag);
// ^----- error here
AllSymbols[tag] = sym;
DESC && setter && defineProperty(ObjectProto, tag, {
...
I'm packaging things with browserify, and even if the bundle only contains require("6to5/polyfill")
, I get this error.
Please add git tags in the form of <major>.<minor>.<patch>
e.g 0.4.10
for each released version, so it's possible for bower to resolve the package version.
If you already have tags locally then git push --tags
should push them to github.
Background: Babel with the "runtime" transformation essentially translates code using Symbol
to use require('core-js/library').Symbol
. The "runtime" transformation seems to be necessary for well-behaved libraries that need ES6 polyfills without polluting the global context or requiring the application to do so.
A problem occurs when a babel-transpiled library (using the runtime transformation) wants to be able to interoperate with iterable objects created by other babel-transpiled code (and they don't happen to share the same instance of babel-runtime/core-js
, which will be the case if they weren't compiled with the same exact version of babel, or if neither babel-transpiled-library depends directly on the other and npm prune
was not used). If a global Symbol.iterator is present, then it works fine because core-js returns that global one if it's present. If a global Symbol.iterator is not available (node 0.10.x, or most non-Chrome and non-Firefox browsers), then the library and the application / other libraries will each have different values for Symbol.iterator, and won't ever recognize objects created by each other as iterable.
Here's an example of an issue with a babel-transpiled library: webmodules/node-iterator#1 . I brainstormed a few ways that the library itself could work around the issue, but they didn't strike me as very good. I think core-js or babel would be better positioned to solve this, though I'm not sure on the specifics, and I'm interested in any discussions.
Possible core-js solutions:
require('core-js/library').Symbol.iterator
could always evaluate to a specific hard-coded string. Relevant: Facebook's regenerator library falls back to using the string "@@iterator" for Symbol.iterator if Symbol isn't available.var core = require("core-js");
var map = new Map();
var key = Object.freeze({});
map.set(key, 123);
This throws an exception, even if your environment has native Maps (node --harmony
) which can handle immutable keys fine.
/Users/chris/Coding/test/node_modules/core-js/library.js:374
return defineProperty(object, key, descriptor(bitmap, value));
^
TypeError: Cannot define property:Symbol(uid)_g.qtbu3c1d5v29be29, object is not extensible.
at defineProperty (native)
at /Users/chris/Coding/test/node_modules/core-js/library.js:374:12
at fastKey (/Users/chris/Coding/test/node_modules/core-js/library.js:1393:17)
at def (/Users/chris/Coding/test/node_modules/core-js/library.js:1401:17)
at getCollection.set (/Users/chris/Coding/test/node_modules/core-js/library.js:1468:14)
at Object.<anonymous> (/Users/chris/Coding/test/index.js:4:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Using the bower "shim.js", I'm crashing in the Symbol
polyfill, on setter && defineProperty(...)
.
// ECMAScript 6 symbols shim
!function(TAG, SymbolRegistry, setter){
// 19.4.1.1 Symbol([description])
if(!isNative(Symbol)){
Symbol = function(description){
// ...
setter && defineProperty(ObjectProto, tag, {
// ...
});
// ...
};
// ...
}(safeSymbol('tag'), {}, true);
setter
is always true
, to start, and defineProperty
doesn't look to be overridden in IE8 (though the DESC
constant seems to be meant to capture this behaviour).
Whether setter
is intended to be DESC
or the internals should be modified, or the functions intended to change the value of setter
are being fired out of order, compared to the rest of the bootstrap process, I'm not sure yet.
I have yet to dig that far (or to check each instance of defineProperty
's use), to see if IE8 is shielded from them.
Sample code:
var foo = function() {};
foo.prototype.foo = "foo";
var bar = function() {};
bar.prototype = Object.create(foo.prototype);
bar.prototype.constructor = bar;
alert(Object.getPrototypeOf(bar.prototype).foo);
This should output "foo", but instead gives "undefined". I know that it won't work in every situation, but where the constructor is correct .constructor.prototype
should return the correct value. This works with es5-sham.
In order to support creating self-contained libraries with 6to5's coreAliasing
transform, I believe this module should not be creating a global variable. Thanks!
Using babel/browser-polyfill.js my app gets so slow it momentarily makes firefox not respond, with the warning:
mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
From babel/babel#1099
'undefined'.startsWith() === true
should be true
.
Described here: facebook/react#3273
grunt build:es6,es6_collections,es6_symbols,iterator --path=custom uglify
in browser:
Uncaught ReferenceError: Dict is not defined
module iterator:
function setFrom(Constructor){
if(Constructor)hidden(Constructor, 'from', function(iterable){
return new Constructor(iterable);
});
}
setFrom(Map);
setFrom(Set);
setFrom(WeakMap);
setFrom(WeakSet);
setFrom(Dict); // <-- here
hidden(String, 'from', function(iterable){
return Array.from(iterable).join('');
});
Please excuse my ignorance for this low level library, but I'm trying to use a native Set
object with 6to5 and have determined that this is probably the library that I should report this issue to.
I have no trouble getting a Set
to work with Chrome, but PhantomJS reports it can't find Set
. Unfortunately, I'm not sure how to run the test suite for this library or I'd happily create a test scenario. Any assistance is extremely helpful.
Kind regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.