diff.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /// <reference path="../../node_modules/monaco-editor-core/monaco.d.ts" />
  2. define(['require'], function (require) {
  3. var container = document.getElementById('container');
  4. var original = monaco.editor.createModel(getOriginalStr(), 'javascript');
  5. var modified = monaco.editor.createModel(getModifiedStr(), 'javascript');
  6. var diffEditor = monaco.editor.createDiffEditor(container, {});
  7. diffEditor.setModel({
  8. original: original,
  9. modified: modified
  10. });
  11. });
  12. function getOriginalStr() {
  13. return [
  14. '/*',
  15. ' © Microsoft. All rights reserved.',
  16. '',
  17. ' This library is supported for use in Windows Tailored Apps only.',
  18. '',
  19. ' Build: 6.2.8100.0',
  20. ' Version: 0.5',
  21. '*/',
  22. '',
  23. '(function (global, undefined) {',
  24. ' "use strict";',
  25. ' undefinedVariable = {};',
  26. ' undefinedVariable.prop = 5;',
  27. '',
  28. ' function initializeProperties(target, members) {',
  29. ' var keys = Object.keys(members);',
  30. ' var properties;',
  31. ' var i, len;',
  32. ' for (i = 0, len = keys.length; i < len; i++) {',
  33. ' var key = keys[i];',
  34. ' var enumerable = key.charCodeAt(0) !== /*_*/95;',
  35. ' var member = members[key];',
  36. " if (member && typeof member === 'object') {",
  37. " if (member.value !== undefined || typeof member.get === 'function' || typeof member.set === 'function') {",
  38. ' if (member.enumerable === undefined) {',
  39. ' member.enumerable = enumerable;',
  40. ' }',
  41. ' properties = properties || {};',
  42. ' properties[key] = member;',
  43. ' continue;',
  44. ' }',
  45. ' }',
  46. ' // These next lines will be deleted',
  47. ' if (!enumerable) {',
  48. ' properties = properties || {};',
  49. ' properties[key] = { value: member, enumerable: enumerable, configurable: true, writable: true }',
  50. ' continue;',
  51. ' }',
  52. ' target[key] = member;',
  53. ' }',
  54. ' if (properties) {',
  55. ' Object.defineProperties(target, properties);',
  56. ' }',
  57. ' }',
  58. '',
  59. ' (function (rootNamespace) {',
  60. '',
  61. ' // Create the rootNamespace in the global namespace',
  62. ' if (!global[rootNamespace]) {',
  63. ' global[rootNamespace] = Object.create(Object.prototype);',
  64. ' }',
  65. '',
  66. ' // Cache the rootNamespace we just created in a local variable',
  67. ' var _rootNamespace = global[rootNamespace];',
  68. ' if (!_rootNamespace.Namespace) {',
  69. ' _rootNamespace.Namespace = Object.create(Object.prototype);',
  70. ' }',
  71. '',
  72. ' function defineWithParent(parentNamespace, name, members) {',
  73. ' /// <summary locid="1">',
  74. ' /// Defines a new namespace with the specified name, under the specified parent namespace.',
  75. ' /// </summary>',
  76. ' /// <param name="parentNamespace" type="Object" locid="2">',
  77. ' /// The parent namespace which will contain the new namespace.',
  78. ' /// </param>',
  79. ' /// <param name="name" type="String" locid="3">',
  80. ' /// Name of the new namespace.',
  81. ' /// </param>',
  82. ' /// <param name="members" type="Object" locid="4">',
  83. ' /// Members in the new namespace.',
  84. ' /// </param>',
  85. ' /// <returns locid="5">',
  86. ' /// The newly defined namespace.',
  87. ' /// </returns>',
  88. ' var currentNamespace = parentNamespace,',
  89. ' namespaceFragments = name.split(".");',
  90. '',
  91. ' for (var i = 0, len = namespaceFragments.length; i < len; i++) {',
  92. ' var namespaceName = namespaceFragments[i];',
  93. ' if (!currentNamespace[namespaceName]) {',
  94. ' Object.defineProperty(currentNamespace, namespaceName,',
  95. ' { value: {}, writable: false, enumerable: true, configurable: true }',
  96. ' );',
  97. ' }',
  98. ' currentNamespace = currentNamespace[namespaceName];',
  99. ' }',
  100. '',
  101. ' if (members) {',
  102. ' initializeProperties(currentNamespace, members);',
  103. ' }',
  104. '',
  105. ' return currentNamespace;',
  106. ' }',
  107. '',
  108. ' function define(name, members) {',
  109. ' /// <summary locid="6">',
  110. ' /// Defines a new namespace with the specified name.',
  111. ' /// </summary>',
  112. ' /// <param name="name" type="String" locid="7">',
  113. ' /// Name of the namespace. This could be a dot-separated nested name.',
  114. ' /// </param>',
  115. ' /// <param name="members" type="Object" locid="4">',
  116. ' /// Members in the new namespace.',
  117. ' /// </param>',
  118. ' /// <returns locid="5">',
  119. ' /// The newly defined namespace.',
  120. ' /// </returns>',
  121. ' return defineWithParent(global, name, members);',
  122. ' }',
  123. '',
  124. ' // Establish members of the "WinJS.Namespace" namespace',
  125. ' Object.defineProperties(_rootNamespace.Namespace, {',
  126. '',
  127. ' defineWithParent: { value: defineWithParent, writable: true, enumerable: true },',
  128. '',
  129. ' define: { value: define, writable: true, enumerable: true }',
  130. '',
  131. ' });',
  132. '',
  133. ' })("WinJS");',
  134. '',
  135. ' (function (WinJS) {',
  136. '',
  137. ' function define(constructor, instanceMembers, staticMembers) {',
  138. ' /// <summary locid="8">',
  139. ' /// Defines a class using the given constructor and with the specified instance members.',
  140. ' /// </summary>',
  141. ' /// <param name="constructor" type="Function" locid="9">',
  142. ' /// A constructor function that will be used to instantiate this class.',
  143. ' /// </param>',
  144. ' /// <param name="instanceMembers" type="Object" locid="10">',
  145. ' /// The set of instance fields, properties and methods to be made available on the class.',
  146. ' /// </param>',
  147. ' /// <param name="staticMembers" type="Object" locid="11">',
  148. ' /// The set of static fields, properties and methods to be made available on the class.',
  149. ' /// </param>',
  150. ' /// <returns type="Function" locid="12">',
  151. ' /// The newly defined class.',
  152. ' /// </returns>',
  153. ' constructor = constructor || function () { };',
  154. ' if (instanceMembers) {',
  155. ' initializeProperties(constructor.prototype, instanceMembers);',
  156. ' }',
  157. ' if (staticMembers) {',
  158. ' initializeProperties(constructor, staticMembers);',
  159. ' }',
  160. ' return constructor;',
  161. ' }',
  162. '',
  163. ' function derive(baseClass, constructor, instanceMembers, staticMembers) {',
  164. ' /// <summary locid="13">',
  165. ' /// Uses prototypal inheritance to create a sub-class based on the supplied baseClass parameter.',
  166. ' /// </summary>',
  167. ' /// <param name="baseClass" type="Function" locid="14">',
  168. ' /// The class to inherit from.',
  169. ' /// </param>',
  170. ' /// <param name="constructor" type="Function" locid="9">',
  171. ' /// A constructor function that will be used to instantiate this class.',
  172. ' /// </param>',
  173. ' /// <param name="instanceMembers" type="Object" locid="10">',
  174. ' /// The set of instance fields, properties and methods to be made available on the class.',
  175. ' /// </param>',
  176. ' /// <param name="staticMembers" type="Object" locid="11">',
  177. ' /// The set of static fields, properties and methods to be made available on the class.',
  178. ' /// </param>',
  179. ' /// <returns type="Function" locid="12">',
  180. ' /// The newly defined class.',
  181. ' /// </returns>',
  182. ' if (baseClass) {',
  183. ' constructor = constructor || function () { };',
  184. ' var basePrototype = baseClass.prototype;',
  185. ' constructor.prototype = Object.create(basePrototype);',
  186. ' Object.defineProperty(constructor.prototype, "_super", { value: basePrototype });',
  187. ' Object.defineProperty(constructor.prototype, "constructor", { value: constructor });',
  188. ' if (instanceMembers) {',
  189. ' initializeProperties(constructor.prototype, instanceMembers);',
  190. ' }',
  191. ' if (staticMembers) {',
  192. ' initializeProperties(constructor, staticMembers);',
  193. ' }',
  194. ' return constructor;',
  195. ' } else {',
  196. ' return define(constructor, instanceMembers, staticMembers);',
  197. ' }',
  198. ' }',
  199. '',
  200. ' function mix(constructor) {',
  201. ' /// <summary locid="15">',
  202. ' /// Defines a class using the given constructor and the union of the set of instance members',
  203. ' /// specified by all the mixin objects. The mixin parameter list can be of variable length.',
  204. ' /// </summary>',
  205. ' /// <param name="constructor" locid="9">',
  206. ' /// A constructor function that will be used to instantiate this class.',
  207. ' /// </param>',
  208. ' /// <returns locid="12">',
  209. ' /// The newly defined class.',
  210. ' /// </returns>',
  211. ' constructor = constructor || function () { };',
  212. ' var i, len;',
  213. ' for (i = 0, len = arguments.length; i < len; i++) {',
  214. ' initializeProperties(constructor.prototype, arguments[i]);',
  215. ' }',
  216. ' return constructor;',
  217. ' }',
  218. '',
  219. ' // Establish members of "WinJS.Class" namespace',
  220. ' WinJS.Namespace.define("WinJS.Class", {',
  221. ' define: define,',
  222. ' derive: derive,',
  223. ' mix: mix',
  224. ' });',
  225. '',
  226. ' })(WinJS);',
  227. '',
  228. '})(this);'
  229. ].join('\n');
  230. }
  231. function getModifiedStr() {
  232. return [
  233. '/*',
  234. ' © Microsoft. All rights reserved.',
  235. '',
  236. ' This library is supported for use in Windows Tailored Apps only.',
  237. '',
  238. ' Build: 6.2.8100.0',
  239. ' Version: 0.5',
  240. '*/',
  241. '',
  242. '// Here are some inserted lines',
  243. '// with some extra comments',
  244. '',
  245. '(function (global, undefined) {',
  246. ' "use strict";',
  247. ' var definedVariable = {};',
  248. ' definedVariable.prop = 5;',
  249. '',
  250. ' function initializeProperties(target, members) {',
  251. ' var keys = Object.keys(members);',
  252. ' var properties;',
  253. ' var i, len;',
  254. ' for (i = 0, len = keys.length; i < len; i++) {',
  255. ' var key = keys[i];',
  256. ' var enumerable = key.charCodeAt(0) !== /*_*/95;',
  257. ' var member = members[key];',
  258. " if (member && typeof member === 'object') {",
  259. " if (member.value !== undefined || typeof member.get === 'function' || typeof member.set === 'function') {",
  260. ' if (member.enumerable === undefined) {',
  261. ' member.enumerable = enumerable;',
  262. ' }',
  263. ' properties = properties || {};',
  264. ' properties[key] = member;',
  265. ' continue;',
  266. ' }',
  267. ' }',
  268. ' target[key] = member;',
  269. ' }',
  270. ' if (properties) {',
  271. ' Object.defineProperties(target, properties);',
  272. ' }',
  273. ' }',
  274. '',
  275. ' (function (rootNamespace) {',
  276. '',
  277. ' // Create the rootNamespace in the global namespace',
  278. ' if (!global[rootNamespace]) {',
  279. ' global[rootNamespace] = Object.create(Object.prototype);',
  280. ' }',
  281. '',
  282. ' // Cache the rootNamespace we just created in a local variable',
  283. ' var _rootNamespace = global[rootNamespace];',
  284. ' if (!_rootNamespace.Namespace) {',
  285. ' _rootNamespace.Namespace = Object.create(Object.prototype);',
  286. ' }',
  287. '',
  288. ' function defineWithParent(parentNamespace, name, members) {',
  289. ' /// <summary locid="1">',
  290. ' /// Defines a new namespace with the specified name, under the specified parent namespace.',
  291. ' /// </summary>',
  292. ' /// <param name="parentNamespace" type="Object" locid="2">',
  293. ' /// The parent namespace which will contain the new namespace.',
  294. ' /// </param>',
  295. ' /// <param name="name" type="String" locid="3">',
  296. ' /// Name of the new namespace.',
  297. ' /// </param>',
  298. ' /// <param name="members" type="Object" locid="4">',
  299. ' /// Members in the new namespace.',
  300. ' /// </param>',
  301. ' /// <returns locid="5">',
  302. ' /// The newly defined namespace.',
  303. ' /// </returns>',
  304. ' var currentNamespace = parentNamespace,',
  305. ' namespaceFragments = name.split(".");',
  306. '',
  307. ' for (var i = 0, len = namespaceFragments.length; i < len; i++) {',
  308. ' var namespaceName = namespaceFragments[i];',
  309. ' if (!currentNamespace[namespaceName]) {',
  310. ' Object.defineProperty(currentNamespace, namespaceName,',
  311. ' { value: {}, writable: false, enumerable: true, configurable: true }',
  312. ' );',
  313. ' }',
  314. ' currentNamespace = currentNamespace[namespaceName];',
  315. ' }',
  316. '',
  317. ' if (members) {',
  318. ' initializeProperties(currentNamespace, members);',
  319. ' }',
  320. '',
  321. ' return currentNamespace;',
  322. ' }',
  323. '',
  324. ' function define(name, members) {',
  325. ' /// <summary locid="6">',
  326. ' /// Defines a new namespace with the specified name.',
  327. ' /// </summary>',
  328. ' /// <param name="name" type="String" locid="7">',
  329. ' /// Name of the namespace. This could be a dot-separated nested name.',
  330. ' /// </param>',
  331. ' /// <param name="members" type="Object" locid="4">',
  332. ' /// Members in the new namespace.',
  333. ' /// </param>',
  334. ' /// <returns locid="5">',
  335. ' /// The newly defined namespace.',
  336. ' /// </returns>',
  337. ' return defineWithParent(global, name, members);',
  338. ' }',
  339. '',
  340. ' // Establish members of the "WinJS.Namespace" namespace',
  341. ' Object.defineProperties(_rootNamespace.Namespace, {',
  342. '',
  343. ' defineWithParent: { value: defineWithParent, writable: true, enumerable: true },',
  344. '',
  345. ' define: { value: define, writable: true, enumerable: true }',
  346. '',
  347. ' });',
  348. '',
  349. ' })("WinJS");',
  350. '',
  351. ' (function (WinJS) {',
  352. '',
  353. ' function define(constructor, instanceMembers, staticMembers) {',
  354. ' /// <summary locid="8">',
  355. ' /// Defines a class using the given constructor and with the specified instance members.',
  356. ' /// </summary>',
  357. ' /// <param name="constructor" type="Function" locid="9">',
  358. ' /// A constructor function that will be used to instantiate this class.',
  359. ' /// </param>',
  360. ' /// <param name="instanceMembers" type="Object" locid="10">',
  361. ' /// The set of instance fields, properties and methods to be made available on the class.',
  362. ' /// </param>',
  363. ' /// <param name="staticMembers" type="Object" locid="11">',
  364. ' /// The set of static fields, properties and methods to be made available on the class.',
  365. ' /// </param>',
  366. ' /// <returns type="Function" locid="12">',
  367. ' /// The newly defined class.',
  368. ' /// </returns>',
  369. ' constructor = constructor || function () { };',
  370. ' if (instanceMembers) {',
  371. ' initializeProperties(constructor.prototype, instanceMembers);',
  372. ' }',
  373. ' if (staticMembers) {',
  374. ' initializeProperties(constructor, staticMembers);',
  375. ' }',
  376. ' return constructor;',
  377. ' }',
  378. '',
  379. ' function derive(baseClass, constructor, instanceMembers, staticMembers) {',
  380. ' /// <summary locid="13">',
  381. ' /// Uses prototypal inheritance to create a sub-class based on the supplied baseClass parameter.',
  382. ' /// </summary>',
  383. ' /// <param name="baseClass" type="Function" locid="14">',
  384. ' /// The class to inherit from.',
  385. ' /// </param>',
  386. ' /// <param name="constructor" type="Function" locid="9">',
  387. ' /// A constructor function that will be used to instantiate this class.',
  388. ' /// </param>',
  389. ' /// <param name="instanceMembers" type="Object" locid="10">',
  390. ' /// The set of instance fields, properties and methods to be made available on the class.',
  391. ' /// </param>',
  392. ' /// <param name="staticMembers" type="Object" locid="11">',
  393. ' /// The set of static fields, properties and methods to be made available on the class.',
  394. ' /// </param>',
  395. ' /// <returns type="Function" locid="12">',
  396. ' /// The newly defined class.',
  397. ' /// </returns>',
  398. ' if (baseClass) {',
  399. ' constructor = constructor || function () { };',
  400. ' var basePrototype = baseClass.prototype;',
  401. ' constructor.prototype = Object.create(basePrototype);',
  402. ' Object.defineProperty(constructor.prototype, "_super", { value: basePrototype });',
  403. ' Object.defineProperty(constructor.prototype, "constructor", { value: constructor });',
  404. ' if (instanceMembers) {',
  405. ' initializeProperties(constructor.prototype, instanceMembers);',
  406. ' }',
  407. ' if (staticMembers) {',
  408. ' initializeProperties(constructor, staticMembers);',
  409. ' }',
  410. ' return constructor;',
  411. ' } else {',
  412. ' return define(constructor, instanceMembers, staticMembers);',
  413. ' }',
  414. ' }',
  415. '',
  416. ' function mix(constructor) {',
  417. ' /// <summary locid="15">',
  418. ' /// Defines a class using the given constructor and the union of the set of instance members',
  419. ' /// specified by all the mixin objects. The mixin parameter list can be of variable length.',
  420. ' /// </summary>',
  421. ' /// <param name="constructor" locid="9">',
  422. ' /// A constructor function that will be used to instantiate this class.',
  423. ' /// </param>',
  424. ' /// <returns locid="12">',
  425. ' /// The newly defined class.',
  426. ' /// </returns>',
  427. ' constructor = constructor || function () { };',
  428. ' var i, len;',
  429. ' for (i = 0, len = arguments.length; i < len; i++) {',
  430. ' initializeProperties(constructor.prototype, arguments[i]);',
  431. ' }',
  432. ' return constructor;',
  433. ' }',
  434. '',
  435. ' // Establish members of "WinJS.Class" namespace',
  436. ' WinJS.Namespace.define("WinJS.Class", {',
  437. ' define: define,',
  438. ' derive: derive,',
  439. ' mix: mix',
  440. ' });',
  441. '',
  442. ' })(WinJS);',
  443. '',
  444. '})(this);'
  445. ].join('\n');
  446. }