Importer-Exporter.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  4. smalltalk.ChunkParser.comment="I am responsible for parsing aStream contents in the chunk format.\x0a\x0a## API\x0a\x0a ChunkParser new\x0a stream: aStream;\x0a nextChunk";
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "nextChunk",
  8. category: 'reading',
  9. fn: function (){
  10. var self=this;
  11. var char,result,chunk;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1,$2,$3;
  14. var $early={};
  15. try {
  16. result=""._writeStream();
  17. _st((function(){
  18. return smalltalk.withContext(function($ctx2) {
  19. char=_st(self["@stream"])._next();
  20. char;
  21. return _st(char)._notNil();
  22. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  23. return smalltalk.withContext(function($ctx2) {
  24. $1=_st(char).__eq("!");
  25. if(smalltalk.assert($1)){
  26. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  27. if(smalltalk.assert($2)){
  28. _st(self["@stream"])._next();
  29. } else {
  30. $3=_st(_st(result)._contents())._trimBoth();
  31. throw $early=[$3];
  32. };
  33. };
  34. return _st(result)._nextPut_(char);
  35. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  36. return nil;
  37. }
  38. catch(e) {if(e===$early)return e[0]; throw e}
  39. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  40. args: [],
  41. source: "nextChunk\x0a\x09\x22The chunk format (Smalltalk Interchange Format or Fileout format)\x0a\x09is a trivial format but can be a bit tricky to understand:\x0a\x09\x09- Uses the exclamation mark as delimiter of chunks.\x0a\x09\x09- Inside a chunk a normal exclamation mark must be doubled.\x0a\x09\x09- A non empty chunk must be a valid Smalltalk expression.\x0a\x09\x09- A chunk on top level with a preceding empty chunk is an instruction chunk:\x0a\x09\x09\x09- The object created by the expression then takes over reading chunks.\x0a\x0a\x09This metod returns next chunk as a String (trimmed), empty String (all whitespace) or nil.\x22\x0a\x0a\x09| char result chunk |\x0a\x09result := '' writeStream.\x0a\x09\x09[char := stream next.\x0a\x09\x09char notNil] whileTrue: [\x0a\x09\x09\x09\x09char = '!' ifTrue: [\x0a\x09\x09\x09\x09\x09\x09stream peek = '!'\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifTrue: [stream next \x22skipping the escape double\x22]\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifFalse: [^result contents trimBoth \x22chunk end marker found\x22]].\x0a\x09\x09\x09\x09result nextPut: char].\x0a\x09^nil \x22a chunk needs to end with !\x22",
  42. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  43. referencedClasses: []
  44. }),
  45. smalltalk.ChunkParser);
  46. smalltalk.addMethod(
  47. smalltalk.method({
  48. selector: "stream:",
  49. category: 'accessing',
  50. fn: function (aStream){
  51. var self=this;
  52. return smalltalk.withContext(function($ctx1) {
  53. self["@stream"]=aStream;
  54. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  55. args: ["aStream"],
  56. source: "stream: aStream\x0a\x09stream := aStream",
  57. messageSends: [],
  58. referencedClasses: []
  59. }),
  60. smalltalk.ChunkParser);
  61. smalltalk.addMethod(
  62. smalltalk.method({
  63. selector: "on:",
  64. category: 'not yet classified',
  65. fn: function (aStream){
  66. var self=this;
  67. return smalltalk.withContext(function($ctx1) {
  68. var $1;
  69. $1=_st(self._new())._stream_(aStream);
  70. return $1;
  71. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  72. args: ["aStream"],
  73. source: "on: aStream\x0a\x09^self new stream: aStream",
  74. messageSends: ["stream:", "new"],
  75. referencedClasses: []
  76. }),
  77. smalltalk.ChunkParser.klass);
  78. smalltalk.addClass('Exporter', smalltalk.Object, [], 'Importer-Exporter');
  79. smalltalk.Exporter.comment="I am responsible for outputting Amber code into a JavaScript string.\x0a\x0aThe generated output is enough to reconstruct the exported data, including Smalltalk source code and other metadata.\x0a\x0a## Use case\x0a\x0aI am typically used to save code outside of the Amber runtime (committing to disk, etc.).\x0a\x0a## API\x0a\x0aUse `#exportAll`, `#exportClass:` or `#exportPackage:` methods.";
  80. smalltalk.addMethod(
  81. smalltalk.method({
  82. selector: "classNameFor:",
  83. category: 'private',
  84. fn: function (aClass){
  85. var self=this;
  86. return smalltalk.withContext(function($ctx1) {
  87. var $2,$3,$1;
  88. $2=_st(aClass)._isMetaclass();
  89. if(smalltalk.assert($2)){
  90. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  91. } else {
  92. $3=_st(aClass)._isNil();
  93. if(smalltalk.assert($3)){
  94. $1="nil";
  95. } else {
  96. $1=_st(aClass)._name();
  97. };
  98. };
  99. return $1;
  100. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  101. args: ["aClass"],
  102. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, '.klass']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  103. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  104. referencedClasses: []
  105. }),
  106. smalltalk.Exporter);
  107. smalltalk.addMethod(
  108. smalltalk.method({
  109. selector: "exportAll",
  110. category: 'fileOut',
  111. fn: function (){
  112. var self=this;
  113. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  114. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  115. return smalltalk.withContext(function($ctx1) {
  116. var $1;
  117. $1=_st($String())._streamContents_((function(stream){
  118. return smalltalk.withContext(function($ctx2) {
  119. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  120. return smalltalk.withContext(function($ctx3) {
  121. return self._exportPackage_on_(pkg,stream);
  122. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  123. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  124. return $1;
  125. }, function($ctx1) {$ctx1.fill(self,"exportAll",{},smalltalk.Exporter)})},
  126. args: [],
  127. source: "exportAll\x0a\x09\x22Export all packages in the system.\x22\x0a\x0a\x09^String streamContents: [:stream |\x0a\x09\x09Smalltalk current packages do: [:pkg |\x0a\x09\x09self exportPackage: pkg on: stream]]",
  128. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  129. referencedClasses: ["Smalltalk", "String"]
  130. }),
  131. smalltalk.Exporter);
  132. smalltalk.addMethod(
  133. smalltalk.method({
  134. selector: "exportClass:on:",
  135. category: 'fileOut',
  136. fn: function (aClass,aStream){
  137. var self=this;
  138. return smalltalk.withContext(function($ctx1) {
  139. self._exportDefinitionOf_on_(aClass,aStream);
  140. _st(self._ownMethodsOfClass_(aClass))._do_((function(each){
  141. return smalltalk.withContext(function($ctx2) {
  142. return self._exportMethod_on_(each,aStream);
  143. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  144. self._exportMetaDefinitionOf_on_(aClass,aStream);
  145. _st(self._ownMethodsOfMetaClass_(aClass))._do_((function(each){
  146. return smalltalk.withContext(function($ctx2) {
  147. return self._exportMethod_on_(each,aStream);
  148. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  149. return self}, function($ctx1) {$ctx1.fill(self,"exportClass:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  150. args: ["aClass", "aStream"],
  151. source: "exportClass: aClass on: aStream\x0a\x09\x22Export a single class. Subclasses override these methods.\x22\x0a\x0a\x09self exportDefinitionOf: aClass on: aStream.\x0a\x09(self ownMethodsOfClass: aClass) do: [ :each |\x0a\x09\x09self exportMethod: each on: aStream\x0a\x09].\x0a\x09self exportMetaDefinitionOf: aClass on: aStream.\x0a\x09(self ownMethodsOfMetaClass: aClass) do: [ :each |\x0a\x09\x09self exportMethod: each on: aStream\x0a\x09].",
  152. messageSends: ["exportDefinitionOf:on:", "do:", "exportMethod:on:", "ownMethodsOfClass:", "exportMetaDefinitionOf:on:", "ownMethodsOfMetaClass:"],
  153. referencedClasses: []
  154. }),
  155. smalltalk.Exporter);
  156. smalltalk.addMethod(
  157. smalltalk.method({
  158. selector: "exportDefinitionOf:on:",
  159. category: 'private',
  160. fn: function (aClass,aStream){
  161. var self=this;
  162. return smalltalk.withContext(function($ctx1) {
  163. var $1,$2,$3,$4,$5,$6,$7;
  164. $1=aStream;
  165. _st($1)._lf();
  166. _st($1)._nextPutAll_("smalltalk.addClass(");
  167. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  168. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  169. $2=_st($1)._nextPutAll_(", [");
  170. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  171. return smalltalk.withContext(function($ctx2) {
  172. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  173. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  174. return smalltalk.withContext(function($ctx2) {
  175. return _st(aStream)._nextPutAll_(", ");
  176. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  177. $3=aStream;
  178. _st($3)._nextPutAll_("], '");
  179. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  180. $4=_st($3)._nextPutAll_(");");
  181. $5=_st(_st(aClass)._comment())._notEmpty();
  182. if(smalltalk.assert($5)){
  183. $6=aStream;
  184. _st($6)._lf();
  185. _st($6)._nextPutAll_("smalltalk.");
  186. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  187. _st($6)._nextPutAll_(".comment=");
  188. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  189. $7=_st($6)._nextPutAll_(";");
  190. $7;
  191. };
  192. _st(aStream)._lf();
  193. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  194. args: ["aClass", "aStream"],
  195. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.';\x0a\x09\x09nextPutAll: (self classNameFor: aClass);\x0a\x09\x09nextPutAll: '.comment=';\x0a\x09\x09nextPutAll: aClass comment asJavascript;\x0a\x09\x09nextPutAll: ';'].\x0a\x09aStream lf",
  196. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  197. referencedClasses: []
  198. }),
  199. smalltalk.Exporter);
  200. smalltalk.addMethod(
  201. smalltalk.method({
  202. selector: "exportMetaDefinitionOf:on:",
  203. category: 'private',
  204. fn: function (aClass,aStream){
  205. var self=this;
  206. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  207. return smalltalk.withContext(function($ctx1) {
  208. var $1,$2,$3;
  209. _st(aStream)._lf();
  210. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  211. if(! smalltalk.assert($1)){
  212. $2=aStream;
  213. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  214. $3=_st($2)._nextPutAll_(".iVarNames = [");
  215. $3;
  216. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  217. return smalltalk.withContext(function($ctx2) {
  218. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  219. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  220. return smalltalk.withContext(function($ctx2) {
  221. return _st(aStream)._nextPutAll_(",");
  222. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  223. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  224. };
  225. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  226. args: ["aClass", "aStream"],
  227. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x09aStream lf.\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass class);\x0a\x09\x09nextPutAll: '.iVarNames = ['.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ','].\x0a\x09\x09aStream nextPutAll: '];', String lf]",
  228. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  229. referencedClasses: ["String"]
  230. }),
  231. smalltalk.Exporter);
  232. smalltalk.addMethod(
  233. smalltalk.method({
  234. selector: "exportMethod:on:",
  235. category: 'private',
  236. fn: function (aMethod,aStream){
  237. var self=this;
  238. return smalltalk.withContext(function($ctx1) {
  239. var $1,$2,$3,$4;
  240. $1=aStream;
  241. _st($1)._nextPutAll_("smalltalk.addMethod(");
  242. _st($1)._lf();
  243. _st($1)._nextPutAll_("smalltalk.method({");
  244. _st($1)._lf();
  245. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  246. _st($1)._lf();
  247. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  248. _st($1)._lf();
  249. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  250. _st($1)._lf();
  251. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  252. _st($1)._lf();
  253. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  254. _st($1)._lf();
  255. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  256. _st($1)._lf();
  257. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  258. $3=aStream;
  259. _st($3)._lf();
  260. _st($3)._nextPutAll_("}),");
  261. _st($3)._lf();
  262. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  263. _st($3)._nextPutAll_(");");
  264. _st($3)._lf();
  265. $4=_st($3)._lf();
  266. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter)})},
  267. args: ["aMethod", "aStream"],
  268. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'category: ''', aMethod category, ''',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'args: ', aMethod arguments asJavascript, ','; lf;\x0a\x09\x09nextPutAll: 'source: ', aMethod source asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'referencedClasses: ', aMethod referencedClasses asJavascript.\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  269. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  270. referencedClasses: []
  271. }),
  272. smalltalk.Exporter);
  273. smalltalk.addMethod(
  274. smalltalk.method({
  275. selector: "exportPackage:on:",
  276. category: 'fileOut',
  277. fn: function (package_,stream){
  278. var self=this;
  279. return smalltalk.withContext(function($ctx1) {
  280. self._exportPackagePrologueOf_on_(package_,stream);
  281. self._exportPackageDefinitionOf_on_(package_,stream);
  282. _st(self._ownClassesOfPackage_(package_))._do_((function(each){
  283. return smalltalk.withContext(function($ctx2) {
  284. return self._exportClass_on_(each,stream);
  285. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  286. _st(self._extensionMethodsOfPackage_(package_))._do_((function(each){
  287. return smalltalk.withContext(function($ctx2) {
  288. return self._exportMethod_on_(each,stream);
  289. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  290. self._exportPackageEpilogueOf_on_(package_,stream);
  291. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{package_:package_,stream:stream},smalltalk.Exporter)})},
  292. args: ["package", "stream"],
  293. source: "exportPackage: package on: stream\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09self exportPackagePrologueOf: package on: stream.\x0a\x09self exportPackageDefinitionOf: package on: stream.\x0a\x0a\x09(self ownClassesOfPackage: package) do: [:each |\x0a\x09\x09self exportClass: each on: stream\x0a\x09].\x0a\x09(self extensionMethodsOfPackage: package) do: [ :each |\x0a\x09\x09self exportMethod: each on: stream\x0a\x09].\x0a\x09self exportPackageEpilogueOf: package on: stream",
  294. messageSends: ["exportPackagePrologueOf:on:", "exportPackageDefinitionOf:on:", "do:", "exportClass:on:", "ownClassesOfPackage:", "exportMethod:on:", "extensionMethodsOfPackage:", "exportPackageEpilogueOf:on:"],
  295. referencedClasses: []
  296. }),
  297. smalltalk.Exporter);
  298. smalltalk.addMethod(
  299. smalltalk.method({
  300. selector: "exportPackageDefinitionOf:on:",
  301. category: 'private',
  302. fn: function (package_,aStream){
  303. var self=this;
  304. return smalltalk.withContext(function($ctx1) {
  305. var $1,$2;
  306. $1=aStream;
  307. _st($1)._nextPutAll_("smalltalk.addPackage(");
  308. _st($1)._nextPutAll_(_st("'".__comma(_st(package_)._name())).__comma("');"));
  309. $2=_st($1)._lf();
  310. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.Exporter)})},
  311. args: ["package", "aStream"],
  312. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', package name, ''');';\x0a\x09\x09lf",
  313. messageSends: ["nextPutAll:", ",", "name", "lf"],
  314. referencedClasses: []
  315. }),
  316. smalltalk.Exporter);
  317. smalltalk.addMethod(
  318. smalltalk.method({
  319. selector: "exportPackageEpilogueOf:on:",
  320. category: 'private',
  321. fn: function (aPackage,aStream){
  322. var self=this;
  323. return smalltalk.withContext(function($ctx1) {
  324. var $1,$2;
  325. $1=aStream;
  326. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  327. $2=_st($1)._lf();
  328. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  329. args: ["aPackage", "aStream"],
  330. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  331. messageSends: ["nextPutAll:", "lf"],
  332. referencedClasses: []
  333. }),
  334. smalltalk.Exporter);
  335. smalltalk.addMethod(
  336. smalltalk.method({
  337. selector: "exportPackagePrologueOf:on:",
  338. category: 'private',
  339. fn: function (aPackage,aStream){
  340. var self=this;
  341. return smalltalk.withContext(function($ctx1) {
  342. var $1,$2;
  343. $1=aStream;
  344. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  345. $2=_st($1)._lf();
  346. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  347. args: ["aPackage", "aStream"],
  348. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  349. messageSends: ["nextPutAll:", "lf"],
  350. referencedClasses: []
  351. }),
  352. smalltalk.Exporter);
  353. smalltalk.addMethod(
  354. smalltalk.method({
  355. selector: "extensionMethodsOfPackage:",
  356. category: 'private',
  357. fn: function (package_){
  358. var self=this;
  359. var name,result;
  360. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  361. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  362. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  363. return smalltalk.withContext(function($ctx1) {
  364. var $1;
  365. name=_st(package_)._name();
  366. result=_st($OrderedCollection())._new();
  367. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  368. return smalltalk.withContext(function($ctx2) {
  369. return _st([each,_st(each)._class()])._do_((function(aClass){
  370. return smalltalk.withContext(function($ctx3) {
  371. return _st(result)._addAll_(_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  372. return smalltalk.withContext(function($ctx4) {
  373. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  374. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._select_((function(method){
  375. return smalltalk.withContext(function($ctx4) {
  376. return _st(_st(method)._category())._match_("^\x5c*".__comma(name));
  377. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx3)})})));
  378. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  379. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  380. $1=result;
  381. return $1;
  382. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{package_:package_,name:name,result:result},smalltalk.Exporter)})},
  383. args: ["package"],
  384. source: "extensionMethodsOfPackage: package\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09result addAll: (((aClass methodDictionary values)\x0a\x09\x09\x09\x09sorted: [:a :b | a selector <= b selector])\x0a\x09\x09\x09\x09select: [:method | method category match: '^\x5c*', name]) ]].\x0a\x09^result",
  385. messageSends: ["name", "new", "do:", "addAll:", "select:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  386. referencedClasses: ["OrderedCollection", "Smalltalk", "Package"]
  387. }),
  388. smalltalk.Exporter);
  389. smalltalk.addMethod(
  390. smalltalk.method({
  391. selector: "ownClassesOfPackage:",
  392. category: 'private',
  393. fn: function (package_){
  394. var self=this;
  395. return smalltalk.withContext(function($ctx1) {
  396. var $1;
  397. $1=_st(_st(package_)._sortedClasses())._asSet();
  398. return $1;
  399. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.Exporter)})},
  400. args: ["package"],
  401. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  402. messageSends: ["asSet", "sortedClasses"],
  403. referencedClasses: []
  404. }),
  405. smalltalk.Exporter);
  406. smalltalk.addMethod(
  407. smalltalk.method({
  408. selector: "ownMethodsOfClass:",
  409. category: 'private',
  410. fn: function (aClass){
  411. var self=this;
  412. return smalltalk.withContext(function($ctx1) {
  413. var $1;
  414. $1=_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  415. return smalltalk.withContext(function($ctx2) {
  416. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  417. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._reject_((function(each){
  418. return smalltalk.withContext(function($ctx2) {
  419. return _st(_st(each)._category())._match_("^\x5c*");
  420. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  421. return $1;
  422. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfClass:",{aClass:aClass},smalltalk.Exporter)})},
  423. args: ["aClass"],
  424. source: "ownMethodsOfClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector])\x0a\x09\x09reject: [:each | (each category match: '^\x5c*')]",
  425. messageSends: ["reject:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary"],
  426. referencedClasses: []
  427. }),
  428. smalltalk.Exporter);
  429. smalltalk.addMethod(
  430. smalltalk.method({
  431. selector: "ownMethodsOfMetaClass:",
  432. category: 'private',
  433. fn: function (aClass){
  434. var self=this;
  435. return smalltalk.withContext(function($ctx1) {
  436. var $1;
  437. $1=self._ownMethodsOfClass_(_st(aClass)._class());
  438. return $1;
  439. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfMetaClass:",{aClass:aClass},smalltalk.Exporter)})},
  440. args: ["aClass"],
  441. source: "ownMethodsOfMetaClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^self ownMethodsOfClass: aClass class",
  442. messageSends: ["ownMethodsOfClass:", "class"],
  443. referencedClasses: []
  444. }),
  445. smalltalk.Exporter);
  446. smalltalk.addClass('ChunkExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  447. smalltalk.ChunkExporter.comment="I am an exporter dedicated to outputting Amber source code in the classic Smalltalk chunk format.\x0a\x0aI do not output any compiled code.";
  448. smalltalk.addMethod(
  449. smalltalk.method({
  450. selector: "chunkEscape:",
  451. category: 'private',
  452. fn: function (aString){
  453. var self=this;
  454. return smalltalk.withContext(function($ctx1) {
  455. var $1;
  456. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  457. return $1;
  458. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.ChunkExporter)})},
  459. args: ["aString"],
  460. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  461. messageSends: ["trimBoth", "replace:with:"],
  462. referencedClasses: []
  463. }),
  464. smalltalk.ChunkExporter);
  465. smalltalk.addMethod(
  466. smalltalk.method({
  467. selector: "classNameFor:",
  468. category: 'private',
  469. fn: function (aClass){
  470. var self=this;
  471. return smalltalk.withContext(function($ctx1) {
  472. var $2,$3,$1;
  473. $2=_st(aClass)._isMetaclass();
  474. if(smalltalk.assert($2)){
  475. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  476. } else {
  477. $3=_st(aClass)._isNil();
  478. if(smalltalk.assert($3)){
  479. $1="nil";
  480. } else {
  481. $1=_st(aClass)._name();
  482. };
  483. };
  484. return $1;
  485. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.ChunkExporter)})},
  486. args: ["aClass"],
  487. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, ' class']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  488. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  489. referencedClasses: []
  490. }),
  491. smalltalk.ChunkExporter);
  492. smalltalk.addMethod(
  493. smalltalk.method({
  494. selector: "exportCategory:on:",
  495. category: 'private',
  496. fn: function (category,aStream){
  497. var self=this;
  498. return smalltalk.withContext(function($ctx1) {
  499. var $1,$2,$3,$4;
  500. $1=aStream;
  501. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(category)._at_("class"))));
  502. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(category)._at_("name"))).__comma("'!"));
  503. _st(_st(_st(category)._at_("methods"))._sorted_((function(a,b){
  504. return smalltalk.withContext(function($ctx2) {
  505. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  506. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(each){
  507. return smalltalk.withContext(function($ctx2) {
  508. return self._exportMethod_on_(each,aStream);
  509. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  510. $3=aStream;
  511. _st($3)._nextPutAll_(" !");
  512. _st($3)._lf();
  513. $4=_st($3)._lf();
  514. return self}, function($ctx1) {$ctx1.fill(self,"exportCategory:on:",{category:category,aStream:aStream},smalltalk.ChunkExporter)})},
  515. args: ["category", "aStream"],
  516. source: "exportCategory: category on: aStream\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: (category at: #class));\x0a\x09\x09nextPutAll: ' methodsFor: ''', (category at: #name), '''!'.\x0a\x09\x09((category at: #methods) sorted: [:a :b | a selector <= b selector]) do: [:each |\x0a\x09\x09\x09\x09self exportMethod: each on: aStream].\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  517. messageSends: ["nextPutAll:", ",", "classNameFor:", "at:", "do:", "exportMethod:on:", "sorted:", "<=", "selector", "lf"],
  518. referencedClasses: []
  519. }),
  520. smalltalk.ChunkExporter);
  521. smalltalk.addMethod(
  522. smalltalk.method({
  523. selector: "exportClass:on:",
  524. category: 'fileOut',
  525. fn: function (aClass,aStream){
  526. var self=this;
  527. return smalltalk.withContext(function($ctx1) {
  528. self._exportDefinitionOf_on_(aClass,aStream);
  529. _st(self._ownCategoriesOfClass_(aClass))._do_((function(each){
  530. return smalltalk.withContext(function($ctx2) {
  531. return self._exportCategory_on_(each,aStream);
  532. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  533. self._exportMetaDefinitionOf_on_(aClass,aStream);
  534. _st(self._ownCategoriesOfMetaClass_(aClass))._do_((function(each){
  535. return smalltalk.withContext(function($ctx2) {
  536. return self._exportCategory_on_(each,aStream);
  537. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  538. return self}, function($ctx1) {$ctx1.fill(self,"exportClass:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  539. args: ["aClass", "aStream"],
  540. source: "exportClass: aClass on: aStream\x0a\x09\x22Export a single class. Subclasses override these methods.\x22\x0a\x0a\x09self exportDefinitionOf: aClass on: aStream.\x0a\x09(self ownCategoriesOfClass: aClass) do: [ :each |\x0a\x09\x09self exportCategory: each on: aStream\x0a\x09].\x0a\x09self exportMetaDefinitionOf: aClass on: aStream.\x0a\x09(self ownCategoriesOfMetaClass: aClass) do: [ :each |\x0a\x09\x09self exportCategory: each on: aStream\x0a\x09].",
  541. messageSends: ["exportDefinitionOf:on:", "do:", "exportCategory:on:", "ownCategoriesOfClass:", "exportMetaDefinitionOf:on:", "ownCategoriesOfMetaClass:"],
  542. referencedClasses: []
  543. }),
  544. smalltalk.ChunkExporter);
  545. smalltalk.addMethod(
  546. smalltalk.method({
  547. selector: "exportDefinitionOf:on:",
  548. category: 'private',
  549. fn: function (aClass,aStream){
  550. var self=this;
  551. return smalltalk.withContext(function($ctx1) {
  552. var $1,$2,$3,$4,$5,$6,$7;
  553. $1=aStream;
  554. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  555. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  556. _st($1)._lf();
  557. _st($1)._tab();
  558. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  559. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  560. return smalltalk.withContext(function($ctx2) {
  561. return _st(aStream)._nextPutAll_(each);
  562. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  563. return smalltalk.withContext(function($ctx2) {
  564. return _st(aStream)._nextPutAll_(" ");
  565. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  566. $3=aStream;
  567. _st($3)._nextPutAll_("'");
  568. _st($3)._lf();
  569. _st($3)._tab();
  570. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  571. $4=_st($3)._lf();
  572. $5=_st(_st(aClass)._comment())._notEmpty();
  573. if(smalltalk.assert($5)){
  574. $6=aStream;
  575. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  576. _st($6)._lf();
  577. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  578. $7=_st($6)._lf();
  579. $7;
  580. };
  581. _st(aStream)._lf();
  582. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  583. args: ["aClass", "aStream"],
  584. source: "exportDefinitionOf: aClass on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ' subclass: #', (self classNameFor: aClass); lf;\x0a\x09\x09tab; nextPutAll: 'instanceVariableNames: '''.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09aStream\x0a\x09\x09nextPutAll: ''''; lf;\x0a\x09\x09tab; nextPutAll: 'package: ''', aClass category, '''!'; lf.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aClass), ' commentStamp!';lf;\x0a\x09\x09nextPutAll: (self chunkEscape: aClass comment), '!';lf].\x0a\x09aStream lf",
  585. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  586. referencedClasses: []
  587. }),
  588. smalltalk.ChunkExporter);
  589. smalltalk.addMethod(
  590. smalltalk.method({
  591. selector: "exportMetaDefinitionOf:on:",
  592. category: 'private',
  593. fn: function (aClass,aStream){
  594. var self=this;
  595. return smalltalk.withContext(function($ctx1) {
  596. var $1,$2,$3,$4,$5;
  597. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  598. if(! smalltalk.assert($1)){
  599. $2=aStream;
  600. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  601. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  602. $3;
  603. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  604. return smalltalk.withContext(function($ctx2) {
  605. return _st(aStream)._nextPutAll_(each);
  606. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  607. return smalltalk.withContext(function($ctx2) {
  608. return _st(aStream)._nextPutAll_(" ");
  609. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  610. $4=aStream;
  611. _st($4)._nextPutAll_("'!");
  612. _st($4)._lf();
  613. $5=_st($4)._lf();
  614. $5;
  615. };
  616. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  617. args: ["aClass", "aStream"],
  618. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: (self classNameFor: aClass class);\x0a\x09\x09\x09nextPutAll: ' instanceVariableNames: '''.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: '''!'; lf; lf]",
  619. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  620. referencedClasses: []
  621. }),
  622. smalltalk.ChunkExporter);
  623. smalltalk.addMethod(
  624. smalltalk.method({
  625. selector: "exportMethod:on:",
  626. category: 'private',
  627. fn: function (aMethod,aStream){
  628. var self=this;
  629. return smalltalk.withContext(function($ctx1) {
  630. var $1,$2;
  631. $1=aStream;
  632. _st($1)._lf();
  633. _st($1)._lf();
  634. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  635. _st($1)._lf();
  636. $2=_st($1)._nextPutAll_("!");
  637. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter)})},
  638. args: ["aMethod", "aStream"],
  639. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  640. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  641. referencedClasses: []
  642. }),
  643. smalltalk.ChunkExporter);
  644. smalltalk.addMethod(
  645. smalltalk.method({
  646. selector: "exportPackage:on:",
  647. category: 'fileOut',
  648. fn: function (package_,stream){
  649. var self=this;
  650. return smalltalk.withContext(function($ctx1) {
  651. self._exportPackageDefinitionOf_on_(package_,stream);
  652. _st(self._ownClassesOfPackage_(package_))._do_((function(each){
  653. return smalltalk.withContext(function($ctx2) {
  654. return self._exportClass_on_(each,stream);
  655. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  656. _st(self._extensionCategoriesOfPackage_(package_))._do_((function(each){
  657. return smalltalk.withContext(function($ctx2) {
  658. return self._exportCategory_on_(each,stream);
  659. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  660. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{package_:package_,stream:stream},smalltalk.ChunkExporter)})},
  661. args: ["package", "stream"],
  662. source: "exportPackage: package on: stream\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09self exportPackageDefinitionOf: package on: stream.\x0a\x0a\x09(self ownClassesOfPackage: package) do: [:each |\x0a\x09\x09self exportClass: each on: stream\x0a\x09].\x0a\x09(self extensionCategoriesOfPackage: package) do: [ :each |\x0a\x09\x09self exportCategory: each on: stream\x0a\x09]",
  663. messageSends: ["exportPackageDefinitionOf:on:", "do:", "exportClass:on:", "ownClassesOfPackage:", "exportCategory:on:", "extensionCategoriesOfPackage:"],
  664. referencedClasses: []
  665. }),
  666. smalltalk.ChunkExporter);
  667. smalltalk.addMethod(
  668. smalltalk.method({
  669. selector: "exportPackageDefinitionOf:on:",
  670. category: 'private',
  671. fn: function (package_,aStream){
  672. var self=this;
  673. return smalltalk.withContext(function($ctx1) {
  674. var $1,$2;
  675. $1=aStream;
  676. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(package_)._name())).__comma("'!"));
  677. $2=_st($1)._lf();
  678. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.ChunkExporter)})},
  679. args: ["package", "aStream"],
  680. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', package name, '''!';\x0a\x09\x09lf",
  681. messageSends: ["nextPutAll:", ",", "name", "lf"],
  682. referencedClasses: []
  683. }),
  684. smalltalk.ChunkExporter);
  685. smalltalk.addMethod(
  686. smalltalk.method({
  687. selector: "extensionCategoriesOfPackage:",
  688. category: 'private',
  689. fn: function (package_){
  690. var self=this;
  691. var name,map,result;
  692. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  693. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  694. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  695. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  696. return smalltalk.withContext(function($ctx1) {
  697. var $1,$2;
  698. name=_st(package_)._name();
  699. result=_st($OrderedCollection())._new();
  700. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  701. return smalltalk.withContext(function($ctx2) {
  702. return _st([each,_st(each)._class()])._do_((function(aClass){
  703. return smalltalk.withContext(function($ctx3) {
  704. map=_st($Dictionary())._new();
  705. map;
  706. _st(aClass)._protocolsDo_((function(category,methods){
  707. return smalltalk.withContext(function($ctx4) {
  708. $1=_st(category)._match_("^\x5c*".__comma(name));
  709. if(smalltalk.assert($1)){
  710. return _st(map)._at_put_(category,methods);
  711. };
  712. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx3)})}));
  713. return _st(result)._addAll_(_st(_st(_st(map)._keys())._sorted_((function(a,b){
  714. return smalltalk.withContext(function($ctx4) {
  715. return _st(a).__lt_eq(b);
  716. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._collect_((function(category){
  717. return smalltalk.withContext(function($ctx4) {
  718. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  719. }, function($ctx4) {$ctx4.fillBlock({category:category},$ctx3)})})));
  720. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  721. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  722. $2=result;
  723. return $2;
  724. }, function($ctx1) {$ctx1.fill(self,"extensionCategoriesOfPackage:",{package_:package_,name:name,map:map,result:result},smalltalk.ChunkExporter)})},
  725. args: ["package"],
  726. source: "extensionCategoriesOfPackage: package\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09map := Dictionary new.\x0a\x09\x09\x09aClass protocolsDo: [:category :methods |\x0a\x09\x09\x09\x09(category match: '^\x5c*', name) ifTrue: [ map at: category put: methods ]].\x0a\x09\x09\x09result addAll: ((map keys sorted: [:a :b | a <= b ]) collect: [:category |\x0a\x09\x09\x09\x09#{ 'methods'->(map at: category). 'name'->category. 'class'->aClass}]) ]].\x0a\x09^result",
  727. messageSends: ["name", "new", "do:", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "addAll:", "collect:", "->", "at:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  728. referencedClasses: ["OrderedCollection", "Dictionary", "Smalltalk", "Package"]
  729. }),
  730. smalltalk.ChunkExporter);
  731. smalltalk.addMethod(
  732. smalltalk.method({
  733. selector: "ownCategoriesOfClass:",
  734. category: 'private',
  735. fn: function (aClass){
  736. var self=this;
  737. var map;
  738. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  739. return smalltalk.withContext(function($ctx1) {
  740. var $1,$2;
  741. map=_st($Dictionary())._new();
  742. _st(aClass)._protocolsDo_((function(category,methods){
  743. return smalltalk.withContext(function($ctx2) {
  744. $1=_st(category)._match_("^\x5c*");
  745. if(! smalltalk.assert($1)){
  746. return _st(map)._at_put_(category,methods);
  747. };
  748. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  749. $2=_st(_st(_st(map)._keys())._sorted_((function(a,b){
  750. return smalltalk.withContext(function($ctx2) {
  751. return _st(a).__lt_eq(b);
  752. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._collect_((function(category){
  753. return smalltalk.withContext(function($ctx2) {
  754. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  755. }, function($ctx2) {$ctx2.fillBlock({category:category},$ctx1)})}));
  756. return $2;
  757. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfClass:",{aClass:aClass,map:map},smalltalk.ChunkExporter)})},
  758. args: ["aClass"],
  759. source: "ownCategoriesOfClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| map |\x0a\x09map := Dictionary new.\x0a\x09aClass protocolsDo: [:category :methods |\x0a\x09\x09(category match: '^\x5c*') ifFalse: [ map at: category put: methods ]].\x0a\x09^(map keys sorted: [:a :b | a <= b ]) collect: [:category |\x0a\x09\x09#{\x0a\x09\x09\x09'methods'->(map at: category).\x0a\x09\x09\x09'name'->category.\x0a\x09\x09\x09'class'->aClass }]",
  760. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "collect:", "->", "at:", "sorted:", "<=", "keys"],
  761. referencedClasses: ["Dictionary"]
  762. }),
  763. smalltalk.ChunkExporter);
  764. smalltalk.addMethod(
  765. smalltalk.method({
  766. selector: "ownCategoriesOfMetaClass:",
  767. category: 'private',
  768. fn: function (aClass){
  769. var self=this;
  770. return smalltalk.withContext(function($ctx1) {
  771. var $1;
  772. $1=self._ownCategoriesOfClass_(_st(aClass)._class());
  773. return $1;
  774. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfMetaClass:",{aClass:aClass},smalltalk.ChunkExporter)})},
  775. args: ["aClass"],
  776. source: "ownCategoriesOfMetaClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09^self ownCategoriesOfClass: aClass class",
  777. messageSends: ["ownCategoriesOfClass:", "class"],
  778. referencedClasses: []
  779. }),
  780. smalltalk.ChunkExporter);
  781. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  782. smalltalk.StrippedExporter.comment="I export Amber code into a JavaScript string, but without any optional associated data like the Amber source code.";
  783. smalltalk.addMethod(
  784. smalltalk.method({
  785. selector: "exportDefinitionOf:on:",
  786. category: 'private',
  787. fn: function (aClass,aStream){
  788. var self=this;
  789. return smalltalk.withContext(function($ctx1) {
  790. var $1,$2,$3,$4;
  791. $1=aStream;
  792. _st($1)._lf();
  793. _st($1)._nextPutAll_("smalltalk.addClass(");
  794. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  795. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  796. $2=_st($1)._nextPutAll_(", [");
  797. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  798. return smalltalk.withContext(function($ctx2) {
  799. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  800. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  801. return smalltalk.withContext(function($ctx2) {
  802. return _st(aStream)._nextPutAll_(", ");
  803. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  804. $3=aStream;
  805. _st($3)._nextPutAll_("], '");
  806. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  807. $4=_st($3)._nextPutAll_(");");
  808. _st(aStream)._lf();
  809. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  810. args: ["aClass", "aStream"],
  811. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aStream lf",
  812. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category"],
  813. referencedClasses: []
  814. }),
  815. smalltalk.StrippedExporter);
  816. smalltalk.addMethod(
  817. smalltalk.method({
  818. selector: "exportMethod:on:",
  819. category: 'private',
  820. fn: function (aMethod,aStream){
  821. var self=this;
  822. return smalltalk.withContext(function($ctx1) {
  823. var $1,$2;
  824. $1=aStream;
  825. _st($1)._nextPutAll_("smalltalk.addMethod(");
  826. _st($1)._lf();
  827. _st($1)._nextPutAll_("smalltalk.method({");
  828. _st($1)._lf();
  829. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  830. _st($1)._lf();
  831. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  832. _st($1)._lf();
  833. _st($1)._nextPutAll_("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  834. _st($1)._nextPutAll_("}),");
  835. _st($1)._lf();
  836. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  837. _st($1)._nextPutAll_(");");
  838. _st($1)._lf();
  839. $2=_st($1)._lf();
  840. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.StrippedExporter)})},
  841. args: ["aMethod", "aStream"],
  842. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  843. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:", "methodClass"],
  844. referencedClasses: []
  845. }),
  846. smalltalk.StrippedExporter);
  847. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  848. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  849. smalltalk.addMethod(
  850. smalltalk.method({
  851. selector: "import:",
  852. category: 'fileIn',
  853. fn: function (aStream){
  854. var self=this;
  855. var chunk,result,parser,lastEmpty;
  856. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  857. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  858. return smalltalk.withContext(function($ctx1) {
  859. var $1,$2;
  860. parser=_st($ChunkParser())._on_(aStream);
  861. lastEmpty=false;
  862. _st((function(){
  863. return smalltalk.withContext(function($ctx2) {
  864. chunk=_st(parser)._nextChunk();
  865. chunk;
  866. return _st(chunk)._isNil();
  867. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  868. return smalltalk.withContext(function($ctx2) {
  869. $1=_st(chunk)._isEmpty();
  870. if(smalltalk.assert($1)){
  871. lastEmpty=true;
  872. return lastEmpty;
  873. } else {
  874. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  875. result;
  876. $2=lastEmpty;
  877. if(smalltalk.assert($2)){
  878. lastEmpty=false;
  879. lastEmpty;
  880. return _st(result)._scanFrom_(parser);
  881. };
  882. };
  883. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  884. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  885. args: ["aStream"],
  886. source: "import: aStream\x0a\x09| chunk result parser lastEmpty |\x0a\x09parser := ChunkParser on: aStream.\x0a\x09lastEmpty := false.\x0a\x09[chunk := parser nextChunk.\x0a\x09chunk isNil] whileFalse: [\x0a\x09\x09chunk isEmpty\x0a\x09\x09\x09ifTrue: [lastEmpty := true]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09result := Compiler new evaluateExpression: chunk.\x0a\x09\x09\x09\x09lastEmpty\x0a\x09\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09lastEmpty := false.\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09result scanFrom: parser]]]",
  887. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  888. referencedClasses: ["ChunkParser", "Compiler"]
  889. }),
  890. smalltalk.Importer);
  891. smalltalk.addClass('PackageHandler', smalltalk.Object, [], 'Importer-Exporter');
  892. smalltalk.PackageHandler.comment="I am responsible for handling package loading and committing.\x0a\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  893. smalltalk.addMethod(
  894. smalltalk.method({
  895. selector: "ajaxPutAt:data:",
  896. category: 'private',
  897. fn: function (aURL,aString){
  898. var self=this;
  899. return smalltalk.withContext(function($ctx1) {
  900. _st(jQuery)._ajax_options_(aURL,smalltalk.HashedCollection._from_(["type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  901. return smalltalk.withContext(function($ctx2) {
  902. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  903. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  904. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  905. args: ["aURL", "aString"],
  906. source: "ajaxPutAt: aURL data: aString\x0a\x09jQuery\x0a\x09\x09ajax: aURL \x0a\x09\x09options: #{ \x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
  907. messageSends: ["ajax:options:", "->", "error:", ",", "responseText"],
  908. referencedClasses: []
  909. }),
  910. smalltalk.PackageHandler);
  911. smalltalk.addMethod(
  912. smalltalk.method({
  913. selector: "commit:",
  914. category: 'committing',
  915. fn: function (aPackage){
  916. var self=this;
  917. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  918. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  919. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  920. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  921. return smalltalk.withContext(function($ctx1) {
  922. _st([_st($Exporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".js")),_st($StrippedExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".deploy.js")),_st($ChunkExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathSt()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".st"))])._do_displayingProgress_((function(commitStrategy){
  923. var fileContents;
  924. return smalltalk.withContext(function($ctx2) {
  925. fileContents=_st($String())._streamContents_((function(stream){
  926. return smalltalk.withContext(function($ctx3) {
  927. return _st(_st(_st(commitStrategy)._key())._new())._exportPackage_on_(aPackage,stream);
  928. }, function($ctx3) {$ctx3.fillBlock({stream:stream},$ctx2)})}));
  929. fileContents;
  930. return self._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  931. }, function($ctx2) {$ctx2.fillBlock({commitStrategy:commitStrategy,fileContents:fileContents},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  932. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  933. args: ["aPackage"],
  934. source: "commit: aPackage\x0a\x09{ \x0a\x09\x09Exporter -> (aPackage commitPathJs, '/', aPackage name, '.js').\x0a\x09\x09StrippedExporter -> (aPackage commitPathJs, '/', aPackage name, '.deploy.js').\x0a\x09\x09ChunkExporter -> (aPackage commitPathSt, '/', aPackage name, '.st')\x0a\x09} \x0a\x09\x09do: [ :commitStrategy|| fileContents |\x0a\x09\x09\x09fileContents := String streamContents: [ :stream |\x0a\x09\x09\x09\x09commitStrategy key new exportPackage: aPackage on: stream ].\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  935. messageSends: ["do:displayingProgress:", "streamContents:", "exportPackage:on:", "new", "key", "ajaxPutAt:data:", "value", ",", "name", "->", "commitPathJs", "commitPathSt"],
  936. referencedClasses: ["String", "Exporter", "StrippedExporter", "ChunkExporter"]
  937. }),
  938. smalltalk.PackageHandler);
  939. smalltalk.addMethod(
  940. smalltalk.method({
  941. selector: "loadPackage:prefix:",
  942. category: 'loading',
  943. fn: function (packageName,aString){
  944. var self=this;
  945. var url;
  946. return smalltalk.withContext(function($ctx1) {
  947. var $1;
  948. url=_st(_st(_st("/".__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  949. _st(jQuery)._ajax_options_(url,smalltalk.HashedCollection._from_(["type".__minus_gt("GET"),"dataType".__minus_gt("script"),"complete".__minus_gt((function(jqXHR,textStatus){
  950. return smalltalk.withContext(function($ctx2) {
  951. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  952. if(smalltalk.assert($1)){
  953. return self._setupPackageNamed_prefix_(packageName,aString);
  954. };
  955. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),"error".__minus_gt((function(){
  956. return smalltalk.withContext(function($ctx2) {
  957. return _st(window)._alert_("Could not load package at: ".__comma(url));
  958. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  959. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.PackageHandler)})},
  960. args: ["packageName", "aString"],
  961. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09jQuery\x0a\x09\x09ajax: url\x0a\x09\x09options: #{\x0a\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09'dataType' -> 'script'.\x0a\x09\x09\x09'complete' -> [ :jqXHR :textStatus |\x0a\x09\x09\x09\x09jqXHR readyState = 4\x0a\x09\x09\x09\x09\x09ifTrue: [ self setupPackageNamed: packageName prefix: aString ] ].\x0a\x09\x09\x09'error' -> [ window alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  962. messageSends: [",", "ajax:options:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  963. referencedClasses: []
  964. }),
  965. smalltalk.PackageHandler);
  966. smalltalk.addMethod(
  967. smalltalk.method({
  968. selector: "loadPackages:prefix:",
  969. category: 'loading',
  970. fn: function (aCollection,aString){
  971. var self=this;
  972. return smalltalk.withContext(function($ctx1) {
  973. _st(aCollection)._do_((function(each){
  974. return smalltalk.withContext(function($ctx2) {
  975. return self._loadPackage_prefix_(each,aString);
  976. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  977. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler)})},
  978. args: ["aCollection", "aString"],
  979. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  980. messageSends: ["do:", "loadPackage:prefix:"],
  981. referencedClasses: []
  982. }),
  983. smalltalk.PackageHandler);
  984. smalltalk.addMethod(
  985. smalltalk.method({
  986. selector: "setupPackageNamed:prefix:",
  987. category: 'private',
  988. fn: function (packageName,aString){
  989. var self=this;
  990. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  991. return smalltalk.withContext(function($ctx1) {
  992. var $1,$2;
  993. $1=_st($Package())._named_(packageName);
  994. _st($1)._setupClasses();
  995. _st($1)._commitPathJs_(_st("/".__comma(aString)).__comma("/js"));
  996. $2=_st($1)._commitPathSt_(_st("/".__comma(aString)).__comma("/st"));
  997. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.PackageHandler)})},
  998. args: ["packageName", "aString"],
  999. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  1000. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  1001. referencedClasses: ["Package"]
  1002. }),
  1003. smalltalk.PackageHandler);
  1004. smalltalk.addMethod(
  1005. smalltalk.method({
  1006. selector: "loadPackages:prefix:",
  1007. category: 'loading',
  1008. fn: function (aCollection,aString){
  1009. var self=this;
  1010. return smalltalk.withContext(function($ctx1) {
  1011. var $1;
  1012. $1=_st(self._new())._loadPackages_prefix_(aCollection,aString);
  1013. return $1;
  1014. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler.klass)})},
  1015. args: ["aCollection", "aString"],
  1016. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  1017. messageSends: ["loadPackages:prefix:", "new"],
  1018. referencedClasses: []
  1019. }),
  1020. smalltalk.PackageHandler.klass);
  1021. smalltalk.addMethod(
  1022. smalltalk.method({
  1023. selector: "commit",
  1024. category: '*Importer-Exporter',
  1025. fn: function (){
  1026. var self=this;
  1027. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1028. return smalltalk.withContext(function($ctx1) {
  1029. var $1;
  1030. $1=_st(_st($PackageHandler())._new())._commit_(self);
  1031. return $1;
  1032. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1033. args: [],
  1034. source: "commit\x0a\x09^ PackageHandler new commit: self",
  1035. messageSends: ["commit:", "new"],
  1036. referencedClasses: ["PackageHandler"]
  1037. }),
  1038. smalltalk.Package);
  1039. })(global_smalltalk,global_nil,global__st);