testconsolidator.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. #! /usr/bin/env node
  2. global.DIGITS_OVERRIDE_FOR_TESTING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
  3. 'use strict';
  4. /*jshint bitwise:true, curly:true, eqeqeq:true, forin:true, immed:true,
  5. latedef:true, newcap:true, noarge:true, noempty:true, nonew:true,
  6. onevar:true, plusplus:true, regexp:true, undef:true, strict:true,
  7. sub:false, trailing:true */
  8. var _,
  9. /**
  10. * NodeJS module for unit testing.
  11. * @namespace
  12. * @type {!TAssert}
  13. * @see http://nodejs.org/docs/v0.6.10/api/all.html#assert
  14. */
  15. oAssert = (/** @type {!TAssert} */ require('assert')),
  16. /**
  17. * Consolidates null, Boolean, and String values found inside an
  18. * <abbr title="abstract syntax tree">AST</abbr>. The object under test.
  19. * @namespace
  20. * @type {!TConsolidator}
  21. */
  22. oConsolidator = (/** @type {!TConsolidator} */ require('../lib/consolidator')),
  23. /**
  24. * The parser of ECMA-262 found in UglifyJS.
  25. * @namespace
  26. * @type {!TParser}
  27. */
  28. oParser = (/** @type {!TParser} */ require('../lib/parse-js')),
  29. /**
  30. * The processor of <abbr title="abstract syntax tree">AST</abbr>s
  31. * found in UglifyJS.
  32. * @namespace
  33. * @type {!TProcessor}
  34. */
  35. oProcessor = (/** @type {!TProcessor} */ require('../lib/process')),
  36. /**
  37. * An instance of an object that allows the traversal of an <abbr
  38. * title="abstract syntax tree">AST</abbr>.
  39. * @type {!TWalker}
  40. */
  41. oWalker,
  42. /**
  43. * A collection of functions for the removal of the scope information
  44. * during the traversal of an <abbr title="abstract syntax tree"
  45. * >AST</abbr>.
  46. * @namespace
  47. * @type {!Object.<string, function(...[*])>}
  48. */
  49. oWalkersPurifiers = {
  50. /**#nocode+*/ // JsDoc Toolkit 2.4.0 hides some of the keys.
  51. /**
  52. * Deletes the scope information from the branch of the abstract
  53. * syntax tree representing the encountered function declaration.
  54. * @param {string} sIdentifier The identifier of the function.
  55. * @param {!Array.<string>} aFormalParameterList Formal parameters.
  56. * @param {!TSyntacticCodeUnit} oFunctionBody Function code.
  57. */
  58. 'defun': function(
  59. sIdentifier,
  60. aFormalParameterList,
  61. oFunctionBody) {
  62. delete oFunctionBody.scope;
  63. },
  64. /**
  65. * Deletes the scope information from the branch of the abstract
  66. * syntax tree representing the encountered function expression.
  67. * @param {?string} sIdentifier The optional identifier of the
  68. * function.
  69. * @param {!Array.<string>} aFormalParameterList Formal parameters.
  70. * @param {!TSyntacticCodeUnit} oFunctionBody Function code.
  71. */
  72. 'function': function(
  73. sIdentifier,
  74. aFormalParameterList,
  75. oFunctionBody) {
  76. delete oFunctionBody.scope;
  77. }
  78. /**#nocode-*/ // JsDoc Toolkit 2.4.0 hides some of the keys.
  79. },
  80. /**
  81. * Initiates the traversal of a source element.
  82. * @param {!TWalker} oWalker An instance of an object that allows the
  83. * traversal of an abstract syntax tree.
  84. * @param {!TSyntacticCodeUnit} oSourceElement A source element from
  85. * which the traversal should commence.
  86. * @return {function(): !TSyntacticCodeUnit} A function that is able to
  87. * initiate the traversal from a given source element.
  88. */
  89. cContext = function(oWalker, oSourceElement) {
  90. /**
  91. * @return {!TSyntacticCodeUnit} A function that is able to
  92. * initiate the traversal from a given source element.
  93. */
  94. var fLambda = function() {
  95. return oWalker.walk(oSourceElement);
  96. };
  97. return fLambda;
  98. },
  99. /**
  100. * A record consisting of configuration for the code generation phase.
  101. * @type {!Object}
  102. */
  103. oCodeGenerationOptions = {
  104. beautify: true
  105. },
  106. /**
  107. * A boolean to track whether all tests have passed.
  108. * @type {boolean}
  109. */
  110. bTestsPassed = true,
  111. /**
  112. * Tests whether consolidation of an ECMAScript program yields expected
  113. * results.
  114. * @param {{
  115. * sTitle: string,
  116. * sInput: string,
  117. * sOutput: string
  118. * }} oUnitTest A record consisting of data about a unit test: its
  119. * name, an ECMAScript program, and, if consolidation is to take
  120. * place, the resulting ECMAScript program.
  121. */
  122. cAssert = function(oUnitTest) {
  123. var _,
  124. /**
  125. * An array-like object representing the <abbr title=
  126. * "abstract syntax tree">AST</abbr> obtained after consolidation.
  127. * @type {!TSyntacticCodeUnit}
  128. */
  129. oSyntacticCodeUnitActual =
  130. oConsolidator.ast_consolidate(oParser.parse(oUnitTest.sInput)),
  131. /**
  132. * An array-like object representing the expected <abbr title=
  133. * "abstract syntax tree">AST</abbr>.
  134. * @type {!TSyntacticCodeUnit}
  135. */
  136. oSyntacticCodeUnitExpected = oParser.parse(
  137. oUnitTest.hasOwnProperty('sOutput') ?
  138. oUnitTest.sOutput : oUnitTest.sInput);
  139. delete oSyntacticCodeUnitActual.scope;
  140. oWalker = oProcessor.ast_walker();
  141. oWalker.with_walkers(
  142. oWalkersPurifiers,
  143. cContext(oWalker, oSyntacticCodeUnitActual));
  144. try {
  145. oAssert.deepEqual(
  146. oSyntacticCodeUnitActual,
  147. oSyntacticCodeUnitExpected);
  148. } catch (oException) {
  149. console.error(
  150. '########## A unit test has failed.\n' +
  151. oUnitTest.sTitle + '\n' +
  152. '##### actual code (' +
  153. oProcessor.gen_code(oSyntacticCodeUnitActual).length +
  154. ' bytes)\n' +
  155. oProcessor.gen_code(
  156. oSyntacticCodeUnitActual,
  157. oCodeGenerationOptions) + '\n' +
  158. '##### expected code (' +
  159. oProcessor.gen_code(oSyntacticCodeUnitExpected).length +
  160. ' bytes)\n' +
  161. oProcessor.gen_code(
  162. oSyntacticCodeUnitExpected,
  163. oCodeGenerationOptions));
  164. bTestsPassed = false;
  165. }
  166. };
  167. [
  168. // 7.6.1 Reserved Words.
  169. {
  170. sTitle:
  171. 'Omission of keywords while choosing an identifier name.',
  172. sInput:
  173. '(function() {' +
  174. ' var a, b, c, d, e, f, g, h, i, j, k, l, m,' +
  175. ' n, o, p, q, r, s, t, u, v, w, x, y, z,' +
  176. ' A, B, C, D, E, F, G, H, I, J, K, L, M,' +
  177. ' N, O, P, Q, R, S, T, U, V, W, X, Y, Z,' +
  178. ' $, _,' +
  179. ' aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am,' +
  180. ' an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az,' +
  181. ' aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM,' +
  182. ' aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ,' +
  183. ' a$, a_,' +
  184. ' ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm,' +
  185. ' bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz,' +
  186. ' bA, bB, bC, bD, bE, bF, bG, bH, bI, bJ, bK, bL, bM,' +
  187. ' bN, bO, bP, bQ, bR, bS, bT, bU, bV, bW, bX, bY, bZ,' +
  188. ' b$, b_,' +
  189. ' ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm,' +
  190. ' cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx, cy, cz,' +
  191. ' cA, cB, cC, cD, cE, cF, cG, cH, cI, cJ, cK, cL, cM,' +
  192. ' cN, cO, cP, cQ, cR, cS, cT, cU, cV, cW, cX, cY, cZ,' +
  193. ' c$, c_,' +
  194. ' da, db, dc, dd, de, df, dg, dh, di, dj, dk, dl, dm,' +
  195. ' dn, dq, dr, ds, dt, du, dv, dw, dx, dy, dz,' +
  196. ' dA, dB, dC, dD, dE, dF, dG, dH, dI, dJ, dK, dL, dM,' +
  197. ' dN, dO, dP, dQ, dR, dS, dT, dU, dV, dW, dX, dY, dZ,' +
  198. ' d$, d_;' +
  199. ' void ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",' +
  200. ' "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];' +
  201. '}());',
  202. sOutput:
  203. '(function() {' +
  204. ' var eb =' +
  205. ' "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",' +
  206. ' a, b, c, d, e, f, g, h, i, j, k, l, m,' +
  207. ' n, o, p, q, r, s, t, u, v, w, x, y, z,' +
  208. ' A, B, C, D, E, F, G, H, I, J, K, L, M,' +
  209. ' N, O, P, Q, R, S, T, U, V, W, X, Y, Z,' +
  210. ' $, _,' +
  211. ' aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am,' +
  212. ' an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az,' +
  213. ' aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM,' +
  214. ' aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ,' +
  215. ' a$, a_,' +
  216. ' ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm,' +
  217. ' bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz,' +
  218. ' bA, bB, bC, bD, bE, bF, bG, bH, bI, bJ, bK, bL, bM,' +
  219. ' bN, bO, bP, bQ, bR, bS, bT, bU, bV, bW, bX, bY, bZ,' +
  220. ' b$, b_,' +
  221. ' ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm,' +
  222. ' cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx, cy, cz,' +
  223. ' cA, cB, cC, cD, cE, cF, cG, cH, cI, cJ, cK, cL, cM,' +
  224. ' cN, cO, cP, cQ, cR, cS, cT, cU, cV, cW, cX, cY, cZ,' +
  225. ' c$, c_,' +
  226. ' da, db, dc, dd, de, df, dg, dh, di, dj, dk, dl, dm,' +
  227. ' dn, dq, dr, ds, dt, du, dv, dw, dx, dy, dz,' +
  228. ' dA, dB, dC, dD, dE, dF, dG, dH, dI, dJ, dK, dL, dM,' +
  229. ' dN, dO, dP, dQ, dR, dS, dT, dU, dV, dW, dX, dY, dZ,' +
  230. ' d$, d_;' +
  231. ' void [eb, eb];' +
  232. '}());'
  233. },
  234. // 7.8.1 Null Literals.
  235. {
  236. sTitle:
  237. 'Evaluation with regard to the null value.',
  238. sInput:
  239. '/*jshint evil:true */' +
  240. '(function() {' +
  241. ' var foo;' +
  242. ' void [null, null, null];' +
  243. '}());' +
  244. 'eval("");' +
  245. '(function() {' +
  246. ' var foo;' +
  247. ' void [null, null];' +
  248. '}());',
  249. sOutput:
  250. '/*jshint evil:true */' +
  251. '(function() {' +
  252. ' var a = null, foo;' +
  253. ' void [a, a, a];' +
  254. '}());' +
  255. 'eval("");' +
  256. '(function() {' +
  257. ' var foo;' +
  258. ' void [null, null];' +
  259. '}());'
  260. },
  261. // 7.8.2 Boolean Literals.
  262. {
  263. sTitle:
  264. 'Evaluation with regard to the false value.',
  265. sInput:
  266. '/*jshint evil:true */' +
  267. '(function() {' +
  268. ' var foo;' +
  269. ' void [false, false, false];' +
  270. '}());' +
  271. 'eval("");' +
  272. '(function() {' +
  273. ' var foo;' +
  274. ' void [false, false];' +
  275. '}());',
  276. sOutput:
  277. '/*jshint evil:true */' +
  278. '(function() {' +
  279. ' var a = false, foo;' +
  280. ' void [a, a, a];' +
  281. '}());' +
  282. 'eval("");' +
  283. '(function() {' +
  284. ' var foo;' +
  285. ' void [false, false];' +
  286. '}());'
  287. },
  288. {
  289. sTitle:
  290. 'Evaluation with regard to the true value.',
  291. sInput:
  292. '/*jshint evil:true */' +
  293. '(function() {' +
  294. ' var foo;' +
  295. ' void [true, true, true];' +
  296. '}());' +
  297. 'eval("");' +
  298. '(function() {' +
  299. ' var foo;' +
  300. ' void [true, true];' +
  301. '}());',
  302. sOutput:
  303. '/*jshint evil:true */' +
  304. '(function() {' +
  305. ' var a = true, foo;' +
  306. ' void [a, a, a];' +
  307. '}());' +
  308. 'eval("");' +
  309. '(function() {' +
  310. ' var foo;' +
  311. ' void [true, true];' +
  312. '}());'
  313. },
  314. // 7.8.4 String Literals.
  315. {
  316. sTitle:
  317. 'Evaluation with regard to the String value of a string literal.',
  318. sInput:
  319. '(function() {' +
  320. ' var foo;' +
  321. ' void ["abcd", "abcd", "abc", "abc"];' +
  322. '}());',
  323. sOutput:
  324. '(function() {' +
  325. ' var a = "abcd", foo;' +
  326. ' void [a, a, "abc", "abc"];' +
  327. '}());'
  328. },
  329. // 7.8.5 Regular Expression Literals.
  330. {
  331. sTitle:
  332. 'Preservation of the pattern of a regular expression literal.',
  333. sInput:
  334. 'void [/abcdefghijklmnopqrstuvwxyz/, /abcdefghijklmnopqrstuvwxyz/];'
  335. },
  336. {
  337. sTitle:
  338. 'Preservation of the flags of a regular expression literal.',
  339. sInput:
  340. 'void [/(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim,' +
  341. ' /(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim,' +
  342. ' /(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim, /(?:)/gim];'
  343. },
  344. // 10.2 Lexical Environments.
  345. {
  346. sTitle:
  347. 'Preservation of identifier names in the same scope.',
  348. sInput:
  349. '/*jshint shadow:true */' +
  350. 'var a;' +
  351. 'function b(i) {' +
  352. '}' +
  353. 'for (var c; 0 === Math.random(););' +
  354. 'for (var d in {});' +
  355. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  356. 'void [b(a), b(c), b(d)];' +
  357. 'void [typeof e];' +
  358. 'i: for (; 0 === Math.random();) {' +
  359. ' if (42 === (new Date()).getMinutes()) {' +
  360. ' continue i;' +
  361. ' } else {' +
  362. ' break i;' +
  363. ' }' +
  364. '}' +
  365. 'try {' +
  366. '} catch (f) {' +
  367. '} finally {' +
  368. '}' +
  369. '(function g(h) {' +
  370. '}());' +
  371. 'void [{' +
  372. ' i: 42,' +
  373. ' "j": 42,' +
  374. ' \'k\': 42' +
  375. '}];' +
  376. 'void ["abcdefghijklmnopqrstuvwxyz"];',
  377. sOutput:
  378. '/*jshint shadow:true */' +
  379. 'var a;' +
  380. 'function b(i) {' +
  381. '}' +
  382. 'for (var c; 0 === Math.random(););' +
  383. 'for (var d in {});' +
  384. '(function() {' +
  385. ' var i = "abcdefghijklmnopqrstuvwxyz";' +
  386. ' void [i];' +
  387. ' void [b(a), b(c), b(d)];' +
  388. ' void [typeof e];' +
  389. ' i: for (; 0 === Math.random();) {' +
  390. ' if (42 === (new Date()).getMinutes()) {' +
  391. ' continue i;' +
  392. ' } else {' +
  393. ' break i;' +
  394. ' }' +
  395. ' }' +
  396. ' try {' +
  397. ' } catch (f) {' +
  398. ' } finally {' +
  399. ' }' +
  400. ' (function g(h) {' +
  401. ' }());' +
  402. ' void [{' +
  403. ' i: 42,' +
  404. ' "j": 42,' +
  405. ' \'k\': 42' +
  406. ' }];' +
  407. ' void [i];' +
  408. '}());'
  409. },
  410. {
  411. sTitle:
  412. 'Preservation of identifier names in nested function code.',
  413. sInput:
  414. '(function() {' +
  415. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  416. ' (function() {' +
  417. ' var a;' +
  418. ' for (var b; 0 === Math.random(););' +
  419. ' for (var c in {});' +
  420. ' void [typeof d];' +
  421. ' h: for (; 0 === Math.random();) {' +
  422. ' if (42 === (new Date()).getMinutes()) {' +
  423. ' continue h;' +
  424. ' } else {' +
  425. ' break h;' +
  426. ' }' +
  427. ' }' +
  428. ' try {' +
  429. ' } catch (e) {' +
  430. ' } finally {' +
  431. ' }' +
  432. ' (function f(g) {' +
  433. ' }());' +
  434. ' void [{' +
  435. ' h: 42,' +
  436. ' "i": 42,' +
  437. ' \'j\': 42' +
  438. ' }];' +
  439. ' }());' +
  440. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  441. '}());',
  442. sOutput:
  443. '(function() {' +
  444. ' var h = "abcdefghijklmnopqrstuvwxyz";' +
  445. ' void [h];' +
  446. ' (function() {' +
  447. ' var a;' +
  448. ' for (var b; 0 === Math.random(););' +
  449. ' for (var c in {});' +
  450. ' void [typeof d];' +
  451. ' h: for (; 0 === Math.random();) {' +
  452. ' if (42 === (new Date()).getMinutes()) {' +
  453. ' continue h;' +
  454. ' } else {' +
  455. ' break h;' +
  456. ' }' +
  457. ' }' +
  458. ' try {' +
  459. ' } catch (e) {' +
  460. ' } finally {' +
  461. ' }' +
  462. ' (function f(g) {' +
  463. ' }());' +
  464. ' void [{' +
  465. ' h: 42,' +
  466. ' "i": 42,' +
  467. ' \'j\': 42' +
  468. ' }];' +
  469. ' }());' +
  470. ' void [h];' +
  471. '}());'
  472. },
  473. {
  474. sTitle:
  475. 'Consolidation of a closure with other source elements.',
  476. sInput:
  477. '(function(foo) {' +
  478. '}("abcdefghijklmnopqrstuvwxyz"));' +
  479. 'void ["abcdefghijklmnopqrstuvwxyz"];',
  480. sOutput:
  481. '(function() {' +
  482. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  483. ' (function(foo) {' +
  484. ' })(a);' +
  485. ' void [a];' +
  486. '}());'
  487. },
  488. {
  489. sTitle:
  490. 'Consolidation of function code instead of a sole closure.',
  491. sInput:
  492. '(function(foo, bar) {' +
  493. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  494. ' "abcdefghijklmnopqrstuvwxyz"];' +
  495. '}("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"));',
  496. sOutput:
  497. '(function(foo, bar) {' +
  498. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  499. ' void [a, a];' +
  500. '}("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"));'
  501. },
  502. // 11.1.5 Object Initialiser.
  503. {
  504. sTitle:
  505. 'Preservation of property names of an object initialiser.',
  506. sInput:
  507. 'var foo = {' +
  508. ' abcdefghijklmnopqrstuvwxyz: 42,' +
  509. ' "zyxwvutsrqponmlkjihgfedcba": 42,' +
  510. ' \'mlkjihgfedcbanopqrstuvwxyz\': 42' +
  511. '};' +
  512. 'void [' +
  513. ' foo.abcdefghijklmnopqrstuvwxyz,' +
  514. ' "zyxwvutsrqponmlkjihgfedcba",' +
  515. ' \'mlkjihgfedcbanopqrstuvwxyz\'' +
  516. '];'
  517. },
  518. {
  519. sTitle:
  520. 'Evaluation with regard to String values derived from identifier ' +
  521. 'names used as property accessors.',
  522. sInput:
  523. '(function() {' +
  524. ' var foo;' +
  525. ' void [' +
  526. ' Math.abcdefghij,' +
  527. ' Math.abcdefghij,' +
  528. ' Math.abcdefghi,' +
  529. ' Math.abcdefghi' +
  530. ' ];' +
  531. '}());',
  532. sOutput:
  533. '(function() {' +
  534. ' var a = "abcdefghij", foo;' +
  535. ' void [' +
  536. ' Math[a],' +
  537. ' Math[a],' +
  538. ' Math.abcdefghi,' +
  539. ' Math.abcdefghi' +
  540. ' ];' +
  541. '}());'
  542. },
  543. // 11.2.1 Property Accessors.
  544. {
  545. sTitle:
  546. 'Preservation of identifiers in the nonterminal MemberExpression.',
  547. sInput:
  548. 'void [' +
  549. ' Math.E,' +
  550. ' Math.LN10,' +
  551. ' Math.LN2,' +
  552. ' Math.LOG2E,' +
  553. ' Math.LOG10E,' +
  554. ' Math.PI,' +
  555. ' Math.SQRT1_2,' +
  556. ' Math.SQRT2,' +
  557. ' Math.abs,' +
  558. ' Math.acos' +
  559. '];'
  560. },
  561. // 12.2 Variable Statement.
  562. {
  563. sTitle:
  564. 'Preservation of the identifier of a variable that is being ' +
  565. 'declared in a variable statement.',
  566. sInput:
  567. '(function() {' +
  568. ' var abcdefghijklmnopqrstuvwxyz;' +
  569. ' void [abcdefghijklmnopqrstuvwxyz];' +
  570. '}());'
  571. },
  572. {
  573. sTitle:
  574. 'Exclusion of a variable statement in global code.',
  575. sInput:
  576. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  577. 'var foo = "abcdefghijklmnopqrstuvwxyz",' +
  578. ' bar = "abcdefghijklmnopqrstuvwxyz";' +
  579. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  580. },
  581. {
  582. sTitle:
  583. 'Exclusion of a variable statement in function code that ' +
  584. 'contains a with statement.',
  585. sInput:
  586. '(function() {' +
  587. ' with ({});' +
  588. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  589. ' var foo;' +
  590. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  591. '}());'
  592. },
  593. {
  594. sTitle:
  595. 'Exclusion of a variable statement in function code that ' +
  596. 'contains a direct call to the eval function.',
  597. sInput:
  598. '/*jshint evil:true */' +
  599. 'void [' +
  600. ' function() {' +
  601. ' eval("");' +
  602. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  603. ' var foo;' +
  604. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  605. ' }' +
  606. '];'
  607. },
  608. {
  609. sTitle:
  610. 'Consolidation within a variable statement in global code.',
  611. sInput:
  612. 'var foo = function() {' +
  613. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  614. ' "abcdefghijklmnopqrstuvwxyz"];' +
  615. '};',
  616. sOutput:
  617. 'var foo = function() {' +
  618. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  619. ' void [a, a];' +
  620. '};'
  621. },
  622. {
  623. sTitle:
  624. 'Consolidation within a variable statement excluded in function ' +
  625. 'code due to the presence of a with statement.',
  626. sInput:
  627. '(function() {' +
  628. ' with ({});' +
  629. ' var foo = function() {' +
  630. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  631. ' "abcdefghijklmnopqrstuvwxyz"];' +
  632. ' };' +
  633. '}());',
  634. sOutput:
  635. '(function() {' +
  636. ' with ({});' +
  637. ' var foo = function() {' +
  638. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  639. ' void [a, a];' +
  640. ' };' +
  641. '}());'
  642. },
  643. {
  644. sTitle:
  645. 'Consolidation within a variable statement excluded in function ' +
  646. 'code due to the presence of a direct call to the eval function.',
  647. sInput:
  648. '/*jshint evil:true */' +
  649. '(function() {' +
  650. ' eval("");' +
  651. ' var foo = function() {' +
  652. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  653. ' "abcdefghijklmnopqrstuvwxyz"];' +
  654. ' };' +
  655. '}());',
  656. sOutput:
  657. '/*jshint evil:true */' +
  658. '(function() {' +
  659. ' eval("");' +
  660. ' var foo = function() {' +
  661. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  662. ' void [a, a];' +
  663. ' };' +
  664. '}());'
  665. },
  666. {
  667. sTitle:
  668. 'Inclusion of a variable statement in function code that ' +
  669. 'contains no with statement and no direct call to the eval ' +
  670. 'function.',
  671. sInput:
  672. '(function() {' +
  673. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  674. ' var foo;' +
  675. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  676. '}());',
  677. sOutput:
  678. '(function() {' +
  679. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  680. ' void [a];' +
  681. ' var foo;' +
  682. ' void [a];' +
  683. '}());'
  684. },
  685. {
  686. sTitle:
  687. 'Ignorance with regard to a variable statement in global code.',
  688. sInput:
  689. 'var foo = "abcdefghijklmnopqrstuvwxyz";' +
  690. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  691. ' "abcdefghijklmnopqrstuvwxyz"];',
  692. sOutput:
  693. 'var foo = "abcdefghijklmnopqrstuvwxyz";' +
  694. '(function() {' +
  695. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  696. ' void [a, a];' +
  697. '}());'
  698. },
  699. // 12.4 Expression Statement.
  700. {
  701. sTitle:
  702. 'Preservation of identifiers in an expression statement.',
  703. sInput:
  704. 'void [typeof abcdefghijklmnopqrstuvwxyz,' +
  705. ' typeof abcdefghijklmnopqrstuvwxyz];'
  706. },
  707. // 12.6.3 The {@code for} Statement.
  708. {
  709. sTitle:
  710. 'Preservation of identifiers in the variable declaration list of ' +
  711. 'a for statement.',
  712. sInput:
  713. 'for (var abcdefghijklmnopqrstuvwxyz; 0 === Math.random(););' +
  714. 'for (var abcdefghijklmnopqrstuvwxyz; 0 === Math.random(););'
  715. },
  716. // 12.6.4 The {@code for-in} Statement.
  717. {
  718. sTitle:
  719. 'Preservation of identifiers in the variable declaration list of ' +
  720. 'a for-in statement.',
  721. sInput:
  722. 'for (var abcdefghijklmnopqrstuvwxyz in {});' +
  723. 'for (var abcdefghijklmnopqrstuvwxyz in {});'
  724. },
  725. // 12.7 The {@code continue} Statement.
  726. {
  727. sTitle:
  728. 'Preservation of the identifier in a continue statement.',
  729. sInput:
  730. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random();) {' +
  731. ' continue abcdefghijklmnopqrstuvwxyz;' +
  732. '}' +
  733. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random();) {' +
  734. ' continue abcdefghijklmnopqrstuvwxyz;' +
  735. '}'
  736. },
  737. // 12.8 The {@code break} Statement.
  738. {
  739. sTitle:
  740. 'Preservation of the identifier in a break statement.',
  741. sInput:
  742. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random();) {' +
  743. ' break abcdefghijklmnopqrstuvwxyz;' +
  744. '}' +
  745. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random();) {' +
  746. ' break abcdefghijklmnopqrstuvwxyz;' +
  747. '}'
  748. },
  749. // 12.9 The {@code return} Statement.
  750. {
  751. sTitle:
  752. 'Exclusion of a return statement in function code that contains ' +
  753. 'a with statement.',
  754. sInput:
  755. '(function() {' +
  756. ' with ({});' +
  757. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  758. ' if (0 === Math.random()) {' +
  759. ' return;' +
  760. ' } else {' +
  761. ' }' +
  762. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  763. '}());'
  764. },
  765. {
  766. sTitle:
  767. 'Exclusion of a return statement in function code that contains ' +
  768. 'a direct call to the eval function.',
  769. sInput:
  770. '/*jshint evil:true */' +
  771. '(function() {' +
  772. ' eval("");' +
  773. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  774. ' if (0 === Math.random()) {' +
  775. ' return;' +
  776. ' } else {' +
  777. ' }' +
  778. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  779. '}());'
  780. },
  781. {
  782. sTitle:
  783. 'Consolidation within a return statement excluded in function ' +
  784. 'code due to the presence of a with statement.',
  785. sInput:
  786. '(function() {' +
  787. ' with ({});' +
  788. ' return function() {' +
  789. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  790. ' "abcdefghijklmnopqrstuvwxyz"];' +
  791. ' };' +
  792. '}());',
  793. sOutput:
  794. '(function() {' +
  795. ' with ({});' +
  796. ' return function() {' +
  797. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  798. ' void [a, a];' +
  799. ' };' +
  800. '}());'
  801. },
  802. {
  803. sTitle:
  804. 'Consolidation within a return statement excluded in function ' +
  805. 'code due to the presence of a direct call to the eval function.',
  806. sInput:
  807. '/*jshint evil:true */' +
  808. '(function() {' +
  809. ' eval("");' +
  810. ' return function() {' +
  811. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  812. ' "abcdefghijklmnopqrstuvwxyz"];' +
  813. ' };' +
  814. '}());',
  815. sOutput:
  816. '/*jshint evil:true */' +
  817. '(function() {' +
  818. ' eval("");' +
  819. ' return function() {' +
  820. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  821. ' void [a, a];' +
  822. ' };' +
  823. '}());'
  824. },
  825. {
  826. sTitle:
  827. 'Inclusion of a return statement in function code that contains ' +
  828. 'no with statement and no direct call to the eval function.',
  829. sInput:
  830. '(function() {' +
  831. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  832. ' if (0 === Math.random()) {' +
  833. ' return;' +
  834. ' } else {' +
  835. ' }' +
  836. ' void ["abcdefghijklmnopqrstuvwxyz"];' +
  837. '}());',
  838. sOutput:
  839. '(function() {' +
  840. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  841. ' void [a];' +
  842. ' if (0 === Math.random()) {' +
  843. ' return;' +
  844. ' } else {' +
  845. ' }' +
  846. ' void [a];' +
  847. '}());'
  848. },
  849. // 12.10 The {@code with} Statement.
  850. {
  851. sTitle:
  852. 'Preservation of the statement in a with statement.',
  853. sInput:
  854. 'with ({}) {' +
  855. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  856. ' "abcdefghijklmnopqrstuvwxyz"];' +
  857. '}'
  858. },
  859. {
  860. sTitle:
  861. 'Exclusion of a with statement in the same syntactic code unit.',
  862. sInput:
  863. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  864. 'with ({' +
  865. ' foo: "abcdefghijklmnopqrstuvwxyz",' +
  866. ' bar: "abcdefghijklmnopqrstuvwxyz"' +
  867. '}) {' +
  868. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  869. ' "abcdefghijklmnopqrstuvwxyz"];' +
  870. '}' +
  871. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  872. },
  873. {
  874. sTitle:
  875. 'Exclusion of a with statement in nested function code.',
  876. sInput:
  877. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  878. '(function() {' +
  879. ' with ({' +
  880. ' foo: "abcdefghijklmnopqrstuvwxyz",' +
  881. ' bar: "abcdefghijklmnopqrstuvwxyz"' +
  882. ' }) {' +
  883. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  884. ' "abcdefghijklmnopqrstuvwxyz"];' +
  885. ' }' +
  886. '}());' +
  887. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  888. },
  889. // 12.12 Labelled Statements.
  890. {
  891. sTitle:
  892. 'Preservation of the label of a labelled statement.',
  893. sInput:
  894. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random(););' +
  895. 'abcdefghijklmnopqrstuvwxyz: for (; 0 === Math.random(););'
  896. },
  897. // 12.14 The {@code try} Statement.
  898. {
  899. sTitle:
  900. 'Preservation of the identifier in the catch clause of a try' +
  901. 'statement.',
  902. sInput:
  903. 'try {' +
  904. '} catch (abcdefghijklmnopqrstuvwxyz) {' +
  905. '} finally {' +
  906. '}' +
  907. 'try {' +
  908. '} catch (abcdefghijklmnopqrstuvwxyz) {' +
  909. '} finally {' +
  910. '}'
  911. },
  912. // 13 Function Definition.
  913. {
  914. sTitle:
  915. 'Preservation of the identifier of a function declaration.',
  916. sInput:
  917. 'function abcdefghijklmnopqrstuvwxyz() {' +
  918. '}' +
  919. 'void [abcdefghijklmnopqrstuvwxyz];'
  920. },
  921. {
  922. sTitle:
  923. 'Preservation of the identifier of a function expression.',
  924. sInput:
  925. 'void [' +
  926. ' function abcdefghijklmnopqrstuvwxyz() {' +
  927. ' },' +
  928. ' function abcdefghijklmnopqrstuvwxyz() {' +
  929. ' }' +
  930. '];'
  931. },
  932. {
  933. sTitle:
  934. 'Preservation of a formal parameter of a function declaration.',
  935. sInput:
  936. 'function foo(abcdefghijklmnopqrstuvwxyz) {' +
  937. '}' +
  938. 'function bar(abcdefghijklmnopqrstuvwxyz) {' +
  939. '}'
  940. },
  941. {
  942. sTitle:
  943. 'Preservation of a formal parameter in a function expression.',
  944. sInput:
  945. 'void [' +
  946. ' function(abcdefghijklmnopqrstuvwxyz) {' +
  947. ' },' +
  948. ' function(abcdefghijklmnopqrstuvwxyz) {' +
  949. ' }' +
  950. '];'
  951. },
  952. {
  953. sTitle:
  954. 'Exclusion of a function declaration.',
  955. sInput:
  956. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  957. 'function foo() {' +
  958. '}' +
  959. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  960. },
  961. {
  962. sTitle:
  963. 'Consolidation within a function declaration.',
  964. sInput:
  965. 'function foo() {' +
  966. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  967. ' "abcdefghijklmnopqrstuvwxyz"];' +
  968. '}',
  969. sOutput:
  970. 'function foo() {' +
  971. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  972. ' void [a, a];' +
  973. '}'
  974. },
  975. // 14 Program.
  976. {
  977. sTitle:
  978. 'Preservation of a program without source elements.',
  979. sInput:
  980. ''
  981. },
  982. // 14.1 Directive Prologues and the Use Strict Directive.
  983. {
  984. sTitle:
  985. 'Preservation of a Directive Prologue in global code.',
  986. sInput:
  987. '"abcdefghijklmnopqrstuvwxyz";' +
  988. '\'zyxwvutsrqponmlkjihgfedcba\';'
  989. },
  990. {
  991. sTitle:
  992. 'Preservation of a Directive Prologue in a function declaration.',
  993. sInput:
  994. 'function foo() {' +
  995. ' "abcdefghijklmnopqrstuvwxyz";' +
  996. ' \'zyxwvutsrqponmlkjihgfedcba\';' +
  997. '}'
  998. },
  999. {
  1000. sTitle:
  1001. 'Preservation of a Directive Prologue in a function expression.',
  1002. sInput:
  1003. 'void [' +
  1004. ' function() {' +
  1005. ' "abcdefghijklmnopqrstuvwxyz";' +
  1006. ' \'zyxwvutsrqponmlkjihgfedcba\';' +
  1007. ' }' +
  1008. '];'
  1009. },
  1010. {
  1011. sTitle:
  1012. 'Ignorance with regard to a Directive Prologue in global code.',
  1013. sInput:
  1014. '"abcdefghijklmnopqrstuvwxyz";' +
  1015. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  1016. ' "abcdefghijklmnopqrstuvwxyz"];',
  1017. sOutput:
  1018. '"abcdefghijklmnopqrstuvwxyz";' +
  1019. '(function() {' +
  1020. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1021. ' void [a, a];' +
  1022. '}());'
  1023. },
  1024. {
  1025. sTitle:
  1026. 'Ignorance with regard to a Directive Prologue in a function' +
  1027. 'declaration.',
  1028. sInput:
  1029. 'function foo() {' +
  1030. ' "abcdefghijklmnopqrstuvwxyz";' +
  1031. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1032. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1033. '}',
  1034. sOutput:
  1035. 'function foo() {' +
  1036. ' "abcdefghijklmnopqrstuvwxyz";' +
  1037. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1038. ' void [a, a];' +
  1039. '}'
  1040. },
  1041. {
  1042. sTitle:
  1043. 'Ignorance with regard to a Directive Prologue in a function' +
  1044. 'expression.',
  1045. sInput:
  1046. '(function() {' +
  1047. ' "abcdefghijklmnopqrstuvwxyz";' +
  1048. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1049. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1050. '}());',
  1051. sOutput:
  1052. '(function() {' +
  1053. ' "abcdefghijklmnopqrstuvwxyz";' +
  1054. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1055. ' void [a, a];' +
  1056. '}());'
  1057. },
  1058. // 15.1 The Global Object.
  1059. {
  1060. sTitle:
  1061. 'Preservation of a property of the global object.',
  1062. sInput:
  1063. 'void [undefined, undefined, undefined, undefined, undefined];'
  1064. },
  1065. // 15.1.2.1.1 Direct Call to Eval.
  1066. {
  1067. sTitle:
  1068. 'Exclusion of a direct call to the eval function in the same ' +
  1069. 'syntactic code unit.',
  1070. sInput:
  1071. '/*jshint evil:true */' +
  1072. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  1073. 'eval("");' +
  1074. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  1075. },
  1076. {
  1077. sTitle:
  1078. 'Exclusion of a direct call to the eval function in nested ' +
  1079. 'function code.',
  1080. sInput:
  1081. '/*jshint evil:true */' +
  1082. 'void ["abcdefghijklmnopqrstuvwxyz"];' +
  1083. '(function() {' +
  1084. ' eval("");' +
  1085. '}());' +
  1086. 'void ["abcdefghijklmnopqrstuvwxyz"];'
  1087. },
  1088. {
  1089. sTitle:
  1090. 'Consolidation within a direct call to the eval function.',
  1091. sInput:
  1092. '/*jshint evil:true */' +
  1093. 'eval(function() {' +
  1094. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1095. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1096. '}());',
  1097. sOutput:
  1098. '/*jshint evil:true */' +
  1099. 'eval(function() {' +
  1100. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1101. ' void [a, a];' +
  1102. '}());'
  1103. },
  1104. // Consolidation proper.
  1105. {
  1106. sTitle:
  1107. 'No consolidation if it does not result in a reduction of the ' +
  1108. 'number of source characters.',
  1109. sInput:
  1110. '(function() {' +
  1111. ' var foo;' +
  1112. ' void ["ab", "ab", "abc", "abc"];' +
  1113. '}());'
  1114. },
  1115. {
  1116. sTitle:
  1117. 'Identification of a range of source elements at the beginning ' +
  1118. 'of global code.',
  1119. sInput:
  1120. '/*jshint evil:true */' +
  1121. '"abcdefghijklmnopqrstuvwxyz";' +
  1122. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  1123. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1124. 'eval("");',
  1125. sOutput:
  1126. '/*jshint evil:true */' +
  1127. '"abcdefghijklmnopqrstuvwxyz";' +
  1128. '(function() {' +
  1129. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1130. ' void [a, a];' +
  1131. '}());' +
  1132. 'eval("");'
  1133. },
  1134. {
  1135. sTitle:
  1136. 'Identification of a range of source elements in the middle of ' +
  1137. 'global code.',
  1138. sInput:
  1139. '/*jshint evil:true */' +
  1140. '"abcdefghijklmnopqrstuvwxyz";' +
  1141. 'eval("");' +
  1142. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  1143. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1144. 'eval("");',
  1145. sOutput:
  1146. '/*jshint evil:true */' +
  1147. '"abcdefghijklmnopqrstuvwxyz";' +
  1148. 'eval("");' +
  1149. '(function() {' +
  1150. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1151. ' void [a, a];' +
  1152. '}());' +
  1153. 'eval("");'
  1154. },
  1155. {
  1156. sTitle:
  1157. 'Identification of a range of source elements at the end of ' +
  1158. 'global code.',
  1159. sInput:
  1160. '/*jshint evil:true */' +
  1161. '"abcdefghijklmnopqrstuvwxyz";' +
  1162. 'eval("");' +
  1163. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  1164. ' "abcdefghijklmnopqrstuvwxyz"];',
  1165. sOutput:
  1166. '/*jshint evil:true */' +
  1167. '"abcdefghijklmnopqrstuvwxyz";' +
  1168. 'eval("");' +
  1169. '(function() {' +
  1170. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1171. ' void [a, a];' +
  1172. '}());'
  1173. },
  1174. {
  1175. sTitle:
  1176. 'Identification of a range of source elements at the beginning ' +
  1177. 'of function code.',
  1178. sInput:
  1179. '/*jshint evil:true */' +
  1180. '(function() {' +
  1181. ' "abcdefghijklmnopqrstuvwxyz";' +
  1182. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1183. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1184. ' eval("");' +
  1185. '}());',
  1186. sOutput:
  1187. '/*jshint evil:true */' +
  1188. '(function() {' +
  1189. ' "abcdefghijklmnopqrstuvwxyz";' +
  1190. ' (function() {' +
  1191. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1192. ' void [a, a];' +
  1193. ' }());' +
  1194. ' eval("");' +
  1195. '}());'
  1196. },
  1197. {
  1198. sTitle:
  1199. 'Identification of a range of source elements in the middle of ' +
  1200. 'function code.',
  1201. sInput:
  1202. '/*jshint evil:true */' +
  1203. '(function() {' +
  1204. ' "abcdefghijklmnopqrstuvwxyz";' +
  1205. ' eval("");' +
  1206. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1207. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1208. ' eval("");' +
  1209. '}());',
  1210. sOutput:
  1211. '/*jshint evil:true */' +
  1212. '(function() {' +
  1213. ' "abcdefghijklmnopqrstuvwxyz";' +
  1214. ' eval("");' +
  1215. ' (function() {' +
  1216. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1217. ' void [a, a];' +
  1218. ' }());' +
  1219. ' eval("");' +
  1220. '}());'
  1221. },
  1222. {
  1223. sTitle:
  1224. 'Identification of a range of source elements at the end of ' +
  1225. 'function code.',
  1226. sInput:
  1227. '/*jshint evil:true */' +
  1228. '(function() {' +
  1229. ' "abcdefghijklmnopqrstuvwxyz";' +
  1230. ' eval("");' +
  1231. ' void ["abcdefghijklmnopqrstuvwxyz",' +
  1232. ' "abcdefghijklmnopqrstuvwxyz"];' +
  1233. '}());',
  1234. sOutput:
  1235. '/*jshint evil:true */' +
  1236. '(function() {' +
  1237. ' "abcdefghijklmnopqrstuvwxyz";' +
  1238. ' eval("");' +
  1239. ' (function() {' +
  1240. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1241. ' void [a, a];' +
  1242. ' }());' +
  1243. '}());'
  1244. },
  1245. {
  1246. sTitle:
  1247. 'Evaluation with regard to String values of String literals and ' +
  1248. 'String values derived from identifier names used as property' +
  1249. 'accessors.',
  1250. sInput:
  1251. '(function() {' +
  1252. ' var foo;' +
  1253. ' void ["abcdefg", Math.abcdefg, "abcdef", Math.abcdef];' +
  1254. '}());',
  1255. sOutput:
  1256. '(function() {' +
  1257. ' var a = "abcdefg", foo;' +
  1258. ' void [a, Math[a], "abcdef", Math.abcdef];' +
  1259. '}());'
  1260. },
  1261. {
  1262. sTitle:
  1263. 'Evaluation with regard to the necessity of adding a variable ' +
  1264. 'statement.',
  1265. sInput:
  1266. '/*jshint evil:true */' +
  1267. '(function() {' +
  1268. ' void ["abcdefgh", "abcdefgh"];' +
  1269. '}());' +
  1270. 'eval("");' +
  1271. '(function() {' +
  1272. ' void ["abcdefg", "abcdefg"];' +
  1273. '}());' +
  1274. 'eval("");' +
  1275. '(function() {' +
  1276. ' var foo;' +
  1277. ' void ["abcd", "abcd"];' +
  1278. '}());',
  1279. sOutput:
  1280. '/*jshint evil:true */' +
  1281. '(function() {' +
  1282. ' var a = "abcdefgh";' +
  1283. ' void [a, a];' +
  1284. '}());' +
  1285. 'eval("");' +
  1286. '(function() {' +
  1287. ' void ["abcdefg", "abcdefg"];' +
  1288. '}());' +
  1289. 'eval("");' +
  1290. '(function() {' +
  1291. ' var a = "abcd", foo;' +
  1292. ' void [a, a];' +
  1293. '}());'
  1294. },
  1295. {
  1296. sTitle:
  1297. 'Evaluation with regard to the necessity of enclosing source ' +
  1298. 'elements.',
  1299. sInput:
  1300. '/*jshint evil:true */' +
  1301. 'void ["abcdefghijklmnopqrstuvwxy", "abcdefghijklmnopqrstuvwxy"];' +
  1302. 'eval("");' +
  1303. 'void ["abcdefghijklmnopqrstuvwx", "abcdefghijklmnopqrstuvwx"];' +
  1304. 'eval("");' +
  1305. '(function() {' +
  1306. ' void ["abcdefgh", "abcdefgh"];' +
  1307. '}());' +
  1308. '(function() {' +
  1309. ' void ["abcdefghijklmnopqrstuvwxy",' +
  1310. ' "abcdefghijklmnopqrstuvwxy"];' +
  1311. ' eval("");' +
  1312. ' void ["abcdefghijklmnopqrstuvwx",' +
  1313. ' "abcdefghijklmnopqrstuvwx"];' +
  1314. ' eval("");' +
  1315. ' (function() {' +
  1316. ' void ["abcdefgh", "abcdefgh"];' +
  1317. ' }());' +
  1318. '}());',
  1319. sOutput:
  1320. '/*jshint evil:true */' +
  1321. '(function() {' +
  1322. ' var a = "abcdefghijklmnopqrstuvwxy";' +
  1323. ' void [a, a];' +
  1324. '}());' +
  1325. 'eval("");' +
  1326. 'void ["abcdefghijklmnopqrstuvwx", "abcdefghijklmnopqrstuvwx"];' +
  1327. 'eval("");' +
  1328. '(function() {' +
  1329. ' var a = "abcdefgh";' +
  1330. ' void [a, a];' +
  1331. '}());' +
  1332. '(function() {' +
  1333. ' (function() {' +
  1334. ' var a = "abcdefghijklmnopqrstuvwxy";' +
  1335. ' void [a, a];' +
  1336. ' }());' +
  1337. ' eval("");' +
  1338. ' void ["abcdefghijklmnopqrstuvwx", "abcdefghijklmnopqrstuvwx"];' +
  1339. ' eval("");' +
  1340. ' (function() {' +
  1341. ' var a = "abcdefgh";' +
  1342. ' void [a, a];' +
  1343. ' }());' +
  1344. '}());'
  1345. },
  1346. {
  1347. sTitle:
  1348. 'Employment of a closure while consolidating in global code.',
  1349. sInput:
  1350. 'void ["abcdefghijklmnopqrstuvwxyz",' +
  1351. ' "abcdefghijklmnopqrstuvwxyz"];',
  1352. sOutput:
  1353. '(function() {' +
  1354. ' var a = "abcdefghijklmnopqrstuvwxyz";' +
  1355. ' void [a, a];' +
  1356. '}());'
  1357. },
  1358. {
  1359. sTitle:
  1360. 'Assignment of a shorter identifier to a value whose ' +
  1361. 'consolidation results in a greater reduction of the number of ' +
  1362. 'source characters.',
  1363. sInput:
  1364. '(function() {' +
  1365. ' var b, c, d, e, f, g, h, i, j, k, l, m,' +
  1366. ' n, o, p, q, r, s, t, u, v, w, x, y, z,' +
  1367. ' A, B, C, D, E, F, G, H, I, J, K, L, M,' +
  1368. ' N, O, P, Q, R, S, T, U, V, W, X, Y, Z,' +
  1369. ' $, _;' +
  1370. ' void ["abcde", "abcde", "edcba", "edcba", "edcba"];' +
  1371. '}());',
  1372. sOutput:
  1373. '(function() {' +
  1374. ' var a = "edcba",' +
  1375. ' b, c, d, e, f, g, h, i, j, k, l, m,' +
  1376. ' n, o, p, q, r, s, t, u, v, w, x, y, z,' +
  1377. ' A, B, C, D, E, F, G, H, I, J, K, L, M,' +
  1378. ' N, O, P, Q, R, S, T, U, V, W, X, Y, Z,' +
  1379. ' $, _;' +
  1380. ' void ["abcde", "abcde", a, a, a];' +
  1381. '}());'
  1382. }
  1383. ].forEach(cAssert);
  1384. process.exit(bTestsPassed ? 0 : 1);