diff.js 17 KB

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