11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif ((!common.hasCrypto) || (!common.hasIntl)) { 51cb0ef41Sopenharmony_ci common.skip('ESLint tests require crypto and Intl'); 61cb0ef41Sopenharmony_ci} 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cicommon.skipIfEslintMissing(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst RuleTester = require('../../tools/node_modules/eslint').RuleTester; 111cb0ef41Sopenharmony_ciconst rule = require('../../tools/eslint-rules/prefer-primordials'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinew RuleTester({ 141cb0ef41Sopenharmony_ci parserOptions: { ecmaVersion: 6 }, 151cb0ef41Sopenharmony_ci env: { es6: true } 161cb0ef41Sopenharmony_ci}) 171cb0ef41Sopenharmony_ci .run('prefer-primordials', rule, { 181cb0ef41Sopenharmony_ci valid: [ 191cb0ef41Sopenharmony_ci 'new Array()', 201cb0ef41Sopenharmony_ci 'JSON.stringify({})', 211cb0ef41Sopenharmony_ci 'class A { *[Symbol.iterator] () { yield "a"; } }', 221cb0ef41Sopenharmony_ci 'const a = { *[Symbol.iterator] () { yield "a"; } }', 231cb0ef41Sopenharmony_ci 'Object.defineProperty(o, Symbol.toStringTag, { value: "o" })', 241cb0ef41Sopenharmony_ci 'parseInt("10")', 251cb0ef41Sopenharmony_ci ` 261cb0ef41Sopenharmony_ci const { Reflect } = primordials; 271cb0ef41Sopenharmony_ci module.exports = function() { 281cb0ef41Sopenharmony_ci const { ownKeys } = Reflect; 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci `, 311cb0ef41Sopenharmony_ci { 321cb0ef41Sopenharmony_ci code: 'const { Array } = primordials; new Array()', 331cb0ef41Sopenharmony_ci options: [{ name: 'Array' }] 341cb0ef41Sopenharmony_ci }, 351cb0ef41Sopenharmony_ci { 361cb0ef41Sopenharmony_ci code: 'const { JSONStringify } = primordials; JSONStringify({})', 371cb0ef41Sopenharmony_ci options: [{ name: 'JSON' }] 381cb0ef41Sopenharmony_ci }, 391cb0ef41Sopenharmony_ci { 401cb0ef41Sopenharmony_ci code: 'const { SymbolFor } = primordials; SymbolFor("xxx")', 411cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }] 421cb0ef41Sopenharmony_ci }, 431cb0ef41Sopenharmony_ci { 441cb0ef41Sopenharmony_ci code: ` 451cb0ef41Sopenharmony_ci const { SymbolIterator } = primordials; 461cb0ef41Sopenharmony_ci class A { *[SymbolIterator] () { yield "a"; } } 471cb0ef41Sopenharmony_ci `, 481cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }] 491cb0ef41Sopenharmony_ci }, 501cb0ef41Sopenharmony_ci { 511cb0ef41Sopenharmony_ci code: ` 521cb0ef41Sopenharmony_ci const { Symbol } = primordials; 531cb0ef41Sopenharmony_ci const a = { *[Symbol.iterator] () { yield "a"; } } 541cb0ef41Sopenharmony_ci `, 551cb0ef41Sopenharmony_ci options: [{ name: 'Symbol', ignore: ['iterator'] }] 561cb0ef41Sopenharmony_ci }, 571cb0ef41Sopenharmony_ci { 581cb0ef41Sopenharmony_ci code: ` 591cb0ef41Sopenharmony_ci const { ObjectDefineProperty, Symbol } = primordials; 601cb0ef41Sopenharmony_ci ObjectDefineProperty(o, Symbol.toStringTag, { value: "o" }); 611cb0ef41Sopenharmony_ci const val = Symbol.toStringTag; 621cb0ef41Sopenharmony_ci const { toStringTag } = Symbol; 631cb0ef41Sopenharmony_ci `, 641cb0ef41Sopenharmony_ci options: [{ name: 'Symbol', ignore: ['toStringTag'] }] 651cb0ef41Sopenharmony_ci }, 661cb0ef41Sopenharmony_ci { 671cb0ef41Sopenharmony_ci code: 'const { Symbol } = primordials; Symbol.for("xxx")', 681cb0ef41Sopenharmony_ci options: [{ name: 'Symbol', ignore: ['for'] }] 691cb0ef41Sopenharmony_ci }, 701cb0ef41Sopenharmony_ci { 711cb0ef41Sopenharmony_ci code: 'const { NumberParseInt } = primordials; NumberParseInt("xxx")', 721cb0ef41Sopenharmony_ci options: [{ name: 'parseInt', into: 'Number' }] 731cb0ef41Sopenharmony_ci }, 741cb0ef41Sopenharmony_ci { 751cb0ef41Sopenharmony_ci code: ` 761cb0ef41Sopenharmony_ci const { ReflectOwnKeys } = primordials; 771cb0ef41Sopenharmony_ci module.exports = function() { 781cb0ef41Sopenharmony_ci ReflectOwnKeys({}) 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci `, 811cb0ef41Sopenharmony_ci options: [{ name: 'Reflect' }], 821cb0ef41Sopenharmony_ci }, 831cb0ef41Sopenharmony_ci { 841cb0ef41Sopenharmony_ci code: 'const { Map } = primordials; new Map()', 851cb0ef41Sopenharmony_ci options: [{ name: 'Map', into: 'Safe' }], 861cb0ef41Sopenharmony_ci }, 871cb0ef41Sopenharmony_ci { 881cb0ef41Sopenharmony_ci code: ` 891cb0ef41Sopenharmony_ci const { Function } = primordials; 901cb0ef41Sopenharmony_ci const rename = Function; 911cb0ef41Sopenharmony_ci const obj = { rename }; 921cb0ef41Sopenharmony_ci `, 931cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 941cb0ef41Sopenharmony_ci }, 951cb0ef41Sopenharmony_ci { 961cb0ef41Sopenharmony_ci code: ` 971cb0ef41Sopenharmony_ci const { Function } = primordials; 981cb0ef41Sopenharmony_ci let rename; 991cb0ef41Sopenharmony_ci rename = Function; 1001cb0ef41Sopenharmony_ci const obj = { rename }; 1011cb0ef41Sopenharmony_ci `, 1021cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 1031cb0ef41Sopenharmony_ci }, 1041cb0ef41Sopenharmony_ci { 1051cb0ef41Sopenharmony_ci code: 'function identifier() {}', 1061cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1071cb0ef41Sopenharmony_ci }, 1081cb0ef41Sopenharmony_ci { 1091cb0ef41Sopenharmony_ci code: 'function* identifier() {}', 1101cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1111cb0ef41Sopenharmony_ci }, 1121cb0ef41Sopenharmony_ci { 1131cb0ef41Sopenharmony_ci code: 'class identifier {}', 1141cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1151cb0ef41Sopenharmony_ci }, 1161cb0ef41Sopenharmony_ci { 1171cb0ef41Sopenharmony_ci code: 'new class { identifier(){} }', 1181cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1191cb0ef41Sopenharmony_ci }, 1201cb0ef41Sopenharmony_ci { 1211cb0ef41Sopenharmony_ci code: 'const a = { identifier: \'4\' }', 1221cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1231cb0ef41Sopenharmony_ci }, 1241cb0ef41Sopenharmony_ci { 1251cb0ef41Sopenharmony_ci code: 'identifier:{const a = 4}', 1261cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1271cb0ef41Sopenharmony_ci }, 1281cb0ef41Sopenharmony_ci { 1291cb0ef41Sopenharmony_ci code: 'switch(0){case identifier:}', 1301cb0ef41Sopenharmony_ci options: [{ name: 'identifier' }] 1311cb0ef41Sopenharmony_ci }, 1321cb0ef41Sopenharmony_ci ], 1331cb0ef41Sopenharmony_ci invalid: [ 1341cb0ef41Sopenharmony_ci { 1351cb0ef41Sopenharmony_ci code: 'new Array()', 1361cb0ef41Sopenharmony_ci options: [{ name: 'Array' }], 1371cb0ef41Sopenharmony_ci errors: [{ message: /const { Array } = primordials/ }] 1381cb0ef41Sopenharmony_ci }, 1391cb0ef41Sopenharmony_ci { 1401cb0ef41Sopenharmony_ci code: 'JSON.parse("{}")', 1411cb0ef41Sopenharmony_ci options: [{ name: 'JSON' }], 1421cb0ef41Sopenharmony_ci errors: [ 1431cb0ef41Sopenharmony_ci { message: /const { JSONParse } = primordials/ }, 1441cb0ef41Sopenharmony_ci ] 1451cb0ef41Sopenharmony_ci }, 1461cb0ef41Sopenharmony_ci { 1471cb0ef41Sopenharmony_ci code: 'const { JSON } = primordials; JSON.parse("{}")', 1481cb0ef41Sopenharmony_ci options: [{ name: 'JSON' }], 1491cb0ef41Sopenharmony_ci errors: [{ message: /const { JSONParse } = primordials/ }] 1501cb0ef41Sopenharmony_ci }, 1511cb0ef41Sopenharmony_ci { 1521cb0ef41Sopenharmony_ci code: 'Symbol.for("xxx")', 1531cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }], 1541cb0ef41Sopenharmony_ci errors: [ 1551cb0ef41Sopenharmony_ci { message: /const { SymbolFor } = primordials/ }, 1561cb0ef41Sopenharmony_ci ] 1571cb0ef41Sopenharmony_ci }, 1581cb0ef41Sopenharmony_ci { 1591cb0ef41Sopenharmony_ci code: 'const { Symbol } = primordials; Symbol.for("xxx")', 1601cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }], 1611cb0ef41Sopenharmony_ci errors: [{ message: /const { SymbolFor } = primordials/ }] 1621cb0ef41Sopenharmony_ci }, 1631cb0ef41Sopenharmony_ci { 1641cb0ef41Sopenharmony_ci code: ` 1651cb0ef41Sopenharmony_ci const { Symbol } = primordials; 1661cb0ef41Sopenharmony_ci class A { *[Symbol.iterator] () { yield "a"; } } 1671cb0ef41Sopenharmony_ci `, 1681cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }], 1691cb0ef41Sopenharmony_ci errors: [{ message: /const { SymbolIterator } = primordials/ }] 1701cb0ef41Sopenharmony_ci }, 1711cb0ef41Sopenharmony_ci { 1721cb0ef41Sopenharmony_ci code: ` 1731cb0ef41Sopenharmony_ci const { Symbol } = primordials; 1741cb0ef41Sopenharmony_ci const a = { *[Symbol.iterator] () { yield "a"; } } 1751cb0ef41Sopenharmony_ci `, 1761cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }], 1771cb0ef41Sopenharmony_ci errors: [{ message: /const { SymbolIterator } = primordials/ }] 1781cb0ef41Sopenharmony_ci }, 1791cb0ef41Sopenharmony_ci { 1801cb0ef41Sopenharmony_ci code: ` 1811cb0ef41Sopenharmony_ci const { ObjectDefineProperty, Symbol } = primordials; 1821cb0ef41Sopenharmony_ci ObjectDefineProperty(o, Symbol.toStringTag, { value: "o" }) 1831cb0ef41Sopenharmony_ci `, 1841cb0ef41Sopenharmony_ci options: [{ name: 'Symbol' }], 1851cb0ef41Sopenharmony_ci errors: [{ message: /const { SymbolToStringTag } = primordials/ }] 1861cb0ef41Sopenharmony_ci }, 1871cb0ef41Sopenharmony_ci { 1881cb0ef41Sopenharmony_ci code: ` 1891cb0ef41Sopenharmony_ci const { Number } = primordials; 1901cb0ef41Sopenharmony_ci Number.parseInt('10') 1911cb0ef41Sopenharmony_ci `, 1921cb0ef41Sopenharmony_ci options: [{ name: 'Number' }], 1931cb0ef41Sopenharmony_ci errors: [{ message: /const { NumberParseInt } = primordials/ }] 1941cb0ef41Sopenharmony_ci }, 1951cb0ef41Sopenharmony_ci { 1961cb0ef41Sopenharmony_ci code: 'parseInt("10")', 1971cb0ef41Sopenharmony_ci options: [{ name: 'parseInt', into: 'Number' }], 1981cb0ef41Sopenharmony_ci errors: [{ message: /const { NumberParseInt } = primordials/ }] 1991cb0ef41Sopenharmony_ci }, 2001cb0ef41Sopenharmony_ci { 2011cb0ef41Sopenharmony_ci code: ` 2021cb0ef41Sopenharmony_ci module.exports = function() { 2031cb0ef41Sopenharmony_ci const { ownKeys } = Reflect; 2041cb0ef41Sopenharmony_ci } 2051cb0ef41Sopenharmony_ci `, 2061cb0ef41Sopenharmony_ci options: [{ name: 'Reflect' }], 2071cb0ef41Sopenharmony_ci errors: [{ message: /const { ReflectOwnKeys } = primordials/ }] 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci { 2101cb0ef41Sopenharmony_ci code: ` 2111cb0ef41Sopenharmony_ci const { Reflect } = primordials; 2121cb0ef41Sopenharmony_ci module.exports = function() { 2131cb0ef41Sopenharmony_ci const { ownKeys } = Reflect; 2141cb0ef41Sopenharmony_ci } 2151cb0ef41Sopenharmony_ci `, 2161cb0ef41Sopenharmony_ci options: [{ name: 'Reflect' }], 2171cb0ef41Sopenharmony_ci errors: [{ message: /const { ReflectOwnKeys } = primordials/ }] 2181cb0ef41Sopenharmony_ci }, 2191cb0ef41Sopenharmony_ci { 2201cb0ef41Sopenharmony_ci code: 'new Map()', 2211cb0ef41Sopenharmony_ci options: [{ name: 'Map', into: 'Safe' }], 2221cb0ef41Sopenharmony_ci errors: [{ message: /const { SafeMap } = primordials/ }] 2231cb0ef41Sopenharmony_ci }, 2241cb0ef41Sopenharmony_ci { 2251cb0ef41Sopenharmony_ci code: ` 2261cb0ef41Sopenharmony_ci const { Function } = primordials; 2271cb0ef41Sopenharmony_ci const noop = Function.prototype; 2281cb0ef41Sopenharmony_ci `, 2291cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 2301cb0ef41Sopenharmony_ci errors: [{ message: /const { FunctionPrototype } = primordials/ }] 2311cb0ef41Sopenharmony_ci }, 2321cb0ef41Sopenharmony_ci { 2331cb0ef41Sopenharmony_ci code: ` 2341cb0ef41Sopenharmony_ci const obj = { Function }; 2351cb0ef41Sopenharmony_ci `, 2361cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 2371cb0ef41Sopenharmony_ci errors: [{ message: /const { Function } = primordials/ }] 2381cb0ef41Sopenharmony_ci }, 2391cb0ef41Sopenharmony_ci { 2401cb0ef41Sopenharmony_ci code: ` 2411cb0ef41Sopenharmony_ci const rename = Function; 2421cb0ef41Sopenharmony_ci `, 2431cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 2441cb0ef41Sopenharmony_ci errors: [{ message: /const { Function } = primordials/ }] 2451cb0ef41Sopenharmony_ci }, 2461cb0ef41Sopenharmony_ci { 2471cb0ef41Sopenharmony_ci code: ` 2481cb0ef41Sopenharmony_ci const rename = Function; 2491cb0ef41Sopenharmony_ci const obj = { rename }; 2501cb0ef41Sopenharmony_ci `, 2511cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 2521cb0ef41Sopenharmony_ci errors: [{ message: /const { Function } = primordials/ }] 2531cb0ef41Sopenharmony_ci }, 2541cb0ef41Sopenharmony_ci { 2551cb0ef41Sopenharmony_ci code: ` 2561cb0ef41Sopenharmony_ci let rename; 2571cb0ef41Sopenharmony_ci rename = Function; 2581cb0ef41Sopenharmony_ci const obj = { rename }; 2591cb0ef41Sopenharmony_ci `, 2601cb0ef41Sopenharmony_ci options: [{ name: 'Function' }], 2611cb0ef41Sopenharmony_ci errors: [{ message: /const { Function } = primordials/ }] 2621cb0ef41Sopenharmony_ci }, 2631cb0ef41Sopenharmony_ci ] 2641cb0ef41Sopenharmony_ci }); 265