diff --git a/.gitmodules b/.gitmodules index 4563909f7e..9f64ea3f37 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/test262"] path = vendor/test262 url = https://github.com/tc39/test262 +[submodule "vendor/compat-table"] + path = vendor/compat-table + url = https://github.com/kangax/compat-table diff --git a/test/kangax.js b/test/kangax.js new file mode 100644 index 0000000000..14d1ef1f54 --- /dev/null +++ b/test/kangax.js @@ -0,0 +1,77 @@ +require("./_helper").assertVendor("compat-table"); + +require("../polyfill"); + +var transform = require("../lib/6to5/transformation/transform"); +var assert = require("assert"); +var data = require("../vendor/compat-table/data-es6"); +var _ = require("lodash"); + + +global.__createIterableObject = function (a, b, c) { + var arr = [a, b, c, ,]; + var iterable = { + next: function() { + return { value: arr.shift(), done: arr.length <= 0 }; + }, + }; + iterable[Symbol.iterator] = function(){ return iterable; } + return iterable; +}; + +var tests = {}; + +_.each(data.tests, function (test, key) { + if (test.subtests) { + _.extend(tests, test.subtests); + } else { + tests[test.name] = test; + } +}); + +suite("kangax/compat-table", function () { + for (var key in tests) { + var data = tests[key]; + + if (data.res._6to5 !== true) continue; + + var exec = data.exec; + var code = exec.toString().match(/[^]*\/\*([^]*)\*\/\}$/); + if (!code) console.log(exec + "", key); + code = code[1]; + + // eval test + if (_.contains(code, "eval") || _.contains(code, "Function")) continue; + + // async test + if (_.contains(code, "function check() {")) continue; + + test(key, function () { + code = transform(code, { + filename: key, + blacklist: ["useStrict"], + optional: ["spec.typeofSymbol", "es6.blockScopingTDZ"] + }).code; + + code = '"use strict";\n' + code; + + var fn; + try { + fn = new Function(code); + } catch (err) { + return; + } + + try { + var fn = new Function(code); + assert.ok(fn.call(undefined)); + } catch (err) { + if (err.message === "Cannot redefine property: name") { + return; + } else { + throw err; + } + } + }); + } +}); diff --git a/vendor/compat-table b/vendor/compat-table new file mode 160000 index 0000000000..40499d421f --- /dev/null +++ b/vendor/compat-table @@ -0,0 +1 @@ +Subproject commit 40499d421f777145d54c999446370d85d5f98186