Skip to content

Commit

Permalink
add fixes for RegExp#toString
Browse files Browse the repository at this point in the history
- by ES6, `RegExp#toString` should be generic and use `.flags` property
- also, old engines has incorrect flags order, related #156
  • Loading branch information
zloirock committed Jan 24, 2016
1 parent 2b40e0b commit b24fe20
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module.exports = {
'es6.array.find',
'es6.array.find-index',
'es6.regexp.constructor',
'es6.regexp.to-string',
'es6.regexp.flags',
'es6.regexp.match',
'es6.regexp.replace',
Expand Down Expand Up @@ -210,7 +211,8 @@ module.exports = {
'es6.object.is-frozen',
'es6.object.is-sealed',
'es6.object.is-extensible',
'es6.string.trim'
'es6.string.trim',
'es6.regexp.to-string'
],
banner: '/**\n' +
' * core-js ' + require('../package').version + '\n' +
Expand Down
1 change: 1 addition & 0 deletions es5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ require('../modules/es6.object.is-frozen');
require('../modules/es6.object.is-sealed');
require('../modules/es6.object.is-extensible');
require('../modules/es6.string.trim');
require('../modules/es6.regexp.to-string');
module.exports = require('../modules/_core');
1 change: 1 addition & 0 deletions es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ require('../modules/es6.array.fill');
require('../modules/es6.array.find');
require('../modules/es6.array.find-index');
require('../modules/es6.regexp.constructor');
require('../modules/es6.regexp.to-string');
require('../modules/es6.regexp.flags');
require('../modules/es6.regexp.match');
require('../modules/es6.regexp.replace');
Expand Down
1 change: 1 addition & 0 deletions es6/regexp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../modules/es6.regexp.constructor');
require('../modules/es6.regexp.to-string');
require('../modules/es6.regexp.flags');
require('../modules/es6.regexp.match');
require('../modules/es6.regexp.replace');
Expand Down
1 change: 1 addition & 0 deletions fn/regexp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../../modules/es6.regexp.constructor');
require('../../modules/es6.regexp.to-string');
require('../../modules/es6.regexp.flags');
require('../../modules/es6.regexp.match');
require('../../modules/es6.regexp.replace');
Expand Down
5 changes: 5 additions & 0 deletions fn/regexp/to-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
require('../../modules/es6.regexp.to-string');
module.exports = function toString(it){
return RegExp.prototype.toString.call(it);
};
1 change: 1 addition & 0 deletions library/es5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ require('../modules/es6.object.is-frozen');
require('../modules/es6.object.is-sealed');
require('../modules/es6.object.is-extensible');
require('../modules/es6.string.trim');
require('../modules/es6.regexp.to-string');
module.exports = require('../modules/_core');
1 change: 1 addition & 0 deletions library/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ require('../modules/es6.array.fill');
require('../modules/es6.array.find');
require('../modules/es6.array.find-index');
require('../modules/es6.regexp.constructor');
require('../modules/es6.regexp.to-string');
require('../modules/es6.regexp.flags');
require('../modules/es6.regexp.match');
require('../modules/es6.regexp.replace');
Expand Down
1 change: 1 addition & 0 deletions library/es6/regexp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../modules/es6.regexp.constructor');
require('../modules/es6.regexp.to-string');
require('../modules/es6.regexp.flags');
require('../modules/es6.regexp.match');
require('../modules/es6.regexp.replace');
Expand Down
1 change: 1 addition & 0 deletions library/fn/regexp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../../modules/es6.regexp.constructor');
require('../../modules/es6.regexp.to-string');
require('../../modules/es6.regexp.flags');
require('../../modules/es6.regexp.match');
require('../../modules/es6.regexp.replace');
Expand Down
5 changes: 5 additions & 0 deletions library/fn/regexp/to-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
require('../../modules/es6.regexp.to-string');
module.exports = function toString(it){
return RegExp.prototype.toString.call(it);
};
Empty file.
1 change: 1 addition & 0 deletions library/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require('./modules/es6.array.fill');
require('./modules/es6.array.find');
require('./modules/es6.array.find-index');
require('./modules/es6.regexp.constructor');
require('./modules/es6.regexp.to-string');
require('./modules/es6.regexp.flags');
require('./modules/es6.regexp.match');
require('./modules/es6.regexp.replace');
Expand Down
13 changes: 13 additions & 0 deletions modules/es6.regexp.to-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
var anObject = require('./_an-object')
, $flags = require('./_flags')
, DESCRIPTORS = require('./_descriptors');
require('./es6.regexp.flags');
// 21.2.5.14 RegExp.prototype.toString()
if(require('./_fails')(function(){
return /./.toString.call({source: 'a', flags: 'b'}) != '/a/b'
}))require('./_redefine')(RegExp.prototype, 'toString', function toString(){
var R = anObject(this);
return '/'.concat(R.source, '/',
'flags' in R ? R.flags : !DESCRIPTORS && R instanceof RegExp ? $flags.call(R) : undefined);
}, true);
Empty file.
1 change: 1 addition & 0 deletions shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require('./modules/es6.array.fill');
require('./modules/es6.array.find');
require('./modules/es6.array.find-index');
require('./modules/es6.regexp.constructor');
require('./modules/es6.regexp.to-string');
require('./modules/es6.regexp.flags');
require('./modules/es6.regexp.match');
require('./modules/es6.regexp.replace');
Expand Down
1 change: 1 addition & 0 deletions tests/commonjs.ls
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ for P in <[.. ../library]>
ok \next of require("#P/fn/string/virtual/iterator").call \qwe
ok \raw of require("#P/fn/string")
ok require("#P/fn/regexp/constructor")(\a \g) + '' is '/a/g'
ok require("#P/fn/regexp/to-string")(/./g) is '/./g'
ok require("#P/fn/regexp/flags")(/./g) is \g
ok typeof require("#P/fn/regexp/match") is \function
ok typeof require("#P/fn/regexp/replace") is \function
Expand Down
47 changes: 47 additions & 0 deletions tests/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/tests/es6.regexp.to-string.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{module, test} = QUnit
module \ES6

test 'RegExp#toString' (assert)!->
{toString} = /./
assert.isFunction toString
assert.arity toString, 0
assert.name toString, \toString
assert.looksNative toString
assert.same String(/pattern/), '/pattern/'
assert.same String(/pattern/i), '/pattern/i'
assert.same String(/pattern/mi), '/pattern/im'
assert.same String(/pattern/im), '/pattern/im'
assert.same String(/pattern/mgi), '/pattern/gim'
assert.same String(new RegExp \pattern), '/pattern/'
assert.same String(new RegExp \pattern \i), '/pattern/i'
assert.same String(new RegExp \pattern \mi), '/pattern/im'
assert.same String(new RegExp \pattern \im), '/pattern/im'
assert.same String(new RegExp \pattern \mgi), '/pattern/gim'
assert.same toString.call(source: \foo, flags: \bar), '/foo/bar'
assert.same toString.call({}), '/undefined/undefined'
if STRICT
assert.throws !-> toString.call 7
assert.throws !-> toString.call \a
assert.throws !-> toString.call no
assert.throws !-> toString.call null
assert.throws !-> toString.call void

0 comments on commit b24fe20

Please sign in to comment.