Importer-Exporter.js 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.addClass('AbstractExporter', smalltalk.Object, [], 'Importer-Exporter');
  4. smalltalk.AbstractExporter.comment="I am an abstract exporter for Amber source code.";
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "chunkEscape:",
  8. category: 'convenience',
  9. fn: function (aString){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) {
  12. var $1;
  13. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  14. return $1;
  15. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.AbstractExporter)})},
  16. args: ["aString"],
  17. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  18. messageSends: ["trimBoth", "replace:with:"],
  19. referencedClasses: []
  20. }),
  21. smalltalk.AbstractExporter);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "classNameFor:",
  25. category: 'convenience',
  26. fn: function (aClass){
  27. var self=this;
  28. return smalltalk.withContext(function($ctx1) {
  29. var $2,$3,$1;
  30. $2=_st(aClass)._isMetaclass();
  31. if(smalltalk.assert($2)){
  32. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  33. } else {
  34. $3=_st(aClass)._isNil();
  35. if(smalltalk.assert($3)){
  36. $1="nil";
  37. } else {
  38. $1=_st(aClass)._name();
  39. };
  40. };
  41. return $1;
  42. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.AbstractExporter)})},
  43. args: ["aClass"],
  44. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, ' class' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  45. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  46. referencedClasses: []
  47. }),
  48. smalltalk.AbstractExporter);
  49. smalltalk.addMethod(
  50. smalltalk.method({
  51. selector: "recipe",
  52. category: 'fileOut',
  53. fn: function (){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. self._subclassResponsibility();
  57. return self}, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.AbstractExporter)})},
  58. args: [],
  59. source: "recipe\x0a\x09\x22Recipe to export a given package.\x22\x0a\x0a\x09self subclassResponsibility",
  60. messageSends: ["subclassResponsibility"],
  61. referencedClasses: []
  62. }),
  63. smalltalk.AbstractExporter);
  64. smalltalk.AbstractExporter.klass.iVarNames = ['default'];
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "default",
  68. category: 'instance creation',
  69. fn: function (){
  70. var self=this;
  71. return smalltalk.withContext(function($ctx1) {
  72. var $2,$1;
  73. $2=self["@default"];
  74. if(($receiver = $2) == nil || $receiver == undefined){
  75. self["@default"]=self._new();
  76. $1=self["@default"];
  77. } else {
  78. $1=$2;
  79. };
  80. return $1;
  81. }, function($ctx1) {$ctx1.fill(self,"default",{},smalltalk.AbstractExporter.klass)})},
  82. args: [],
  83. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  84. messageSends: ["ifNil:", "new"],
  85. referencedClasses: []
  86. }),
  87. smalltalk.AbstractExporter.klass);
  88. smalltalk.addClass('ChunkExporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  89. 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.";
  90. smalltalk.addMethod(
  91. smalltalk.method({
  92. selector: "exportCategoryEpilogueOf:on:",
  93. category: 'output',
  94. fn: function (aCategory,aStream){
  95. var self=this;
  96. return smalltalk.withContext(function($ctx1) {
  97. var $1,$2;
  98. $1=aStream;
  99. _st($1)._nextPutAll_(" !");
  100. _st($1)._lf();
  101. $2=_st($1)._lf();
  102. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryEpilogueOf:on:",{aCategory:aCategory,aStream:aStream},smalltalk.ChunkExporter)})},
  103. args: ["aCategory", "aStream"],
  104. source: "exportCategoryEpilogueOf: aCategory on: aStream\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  105. messageSends: ["nextPutAll:", "lf"],
  106. referencedClasses: []
  107. }),
  108. smalltalk.ChunkExporter);
  109. smalltalk.addMethod(
  110. smalltalk.method({
  111. selector: "exportCategoryPrologueOf:on:",
  112. category: 'output',
  113. fn: function (aCategory,aStream){
  114. var self=this;
  115. return smalltalk.withContext(function($ctx1) {
  116. var $1,$2;
  117. $1=aStream;
  118. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(aCategory)._theClass())));
  119. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(aCategory)._name())).__comma("'!"));
  120. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryPrologueOf:on:",{aCategory:aCategory,aStream:aStream},smalltalk.ChunkExporter)})},
  121. args: ["aCategory", "aStream"],
  122. source: "exportCategoryPrologueOf: aCategory on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aCategory theClass);\x0a\x09\x09nextPutAll: ' methodsFor: ''', aCategory name, '''!'",
  123. messageSends: ["nextPutAll:", ",", "classNameFor:", "theClass", "name"],
  124. referencedClasses: []
  125. }),
  126. smalltalk.ChunkExporter);
  127. smalltalk.addMethod(
  128. smalltalk.method({
  129. selector: "exportDefinitionOf:on:",
  130. category: 'output',
  131. fn: function (aClass,aStream){
  132. var self=this;
  133. return smalltalk.withContext(function($ctx1) {
  134. var $1,$2,$3,$4,$5,$6,$7;
  135. $1=aStream;
  136. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  137. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  138. _st($1)._lf();
  139. _st($1)._tab();
  140. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  141. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  142. return smalltalk.withContext(function($ctx2) {
  143. return _st(aStream)._nextPutAll_(each);
  144. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  145. return smalltalk.withContext(function($ctx2) {
  146. return _st(aStream)._nextPutAll_(" ");
  147. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  148. $3=aStream;
  149. _st($3)._nextPutAll_("'");
  150. _st($3)._lf();
  151. _st($3)._tab();
  152. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  153. $4=_st($3)._lf();
  154. $5=_st(_st(aClass)._comment())._notEmpty();
  155. if(smalltalk.assert($5)){
  156. $6=aStream;
  157. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  158. _st($6)._lf();
  159. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  160. $7=_st($6)._lf();
  161. $7;
  162. };
  163. _st(aStream)._lf();
  164. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  165. args: ["aClass", "aStream"],
  166. 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",
  167. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  168. referencedClasses: []
  169. }),
  170. smalltalk.ChunkExporter);
  171. smalltalk.addMethod(
  172. smalltalk.method({
  173. selector: "exportMetaDefinitionOf:on:",
  174. category: 'output',
  175. fn: function (aClass,aStream){
  176. var self=this;
  177. return smalltalk.withContext(function($ctx1) {
  178. var $1,$2,$3,$4,$5;
  179. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  180. if(! smalltalk.assert($1)){
  181. $2=aStream;
  182. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  183. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  184. $3;
  185. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  186. return smalltalk.withContext(function($ctx2) {
  187. return _st(aStream)._nextPutAll_(each);
  188. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  189. return smalltalk.withContext(function($ctx2) {
  190. return _st(aStream)._nextPutAll_(" ");
  191. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  192. $4=aStream;
  193. _st($4)._nextPutAll_("'!");
  194. _st($4)._lf();
  195. $5=_st($4)._lf();
  196. $5;
  197. };
  198. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  199. args: ["aClass", "aStream"],
  200. 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]",
  201. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  202. referencedClasses: []
  203. }),
  204. smalltalk.ChunkExporter);
  205. smalltalk.addMethod(
  206. smalltalk.method({
  207. selector: "exportMethod:on:",
  208. category: 'output',
  209. fn: function (aMethod,aStream){
  210. var self=this;
  211. return smalltalk.withContext(function($ctx1) {
  212. var $1,$2;
  213. $1=aStream;
  214. _st($1)._lf();
  215. _st($1)._lf();
  216. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  217. _st($1)._lf();
  218. $2=_st($1)._nextPutAll_("!");
  219. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter)})},
  220. args: ["aMethod", "aStream"],
  221. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  222. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  223. referencedClasses: []
  224. }),
  225. smalltalk.ChunkExporter);
  226. smalltalk.addMethod(
  227. smalltalk.method({
  228. selector: "exportPackageDefinitionOf:on:",
  229. category: 'output',
  230. fn: function (aPackage,aStream){
  231. var self=this;
  232. return smalltalk.withContext(function($ctx1) {
  233. var $1,$2;
  234. $1=aStream;
  235. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(aPackage)._name())).__comma("'!"));
  236. $2=_st($1)._lf();
  237. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.ChunkExporter)})},
  238. args: ["aPackage", "aStream"],
  239. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', aPackage name, '''!';\x0a\x09\x09lf",
  240. messageSends: ["nextPutAll:", ",", "name", "lf"],
  241. referencedClasses: []
  242. }),
  243. smalltalk.ChunkExporter);
  244. smalltalk.addMethod(
  245. smalltalk.method({
  246. selector: "extensionCategoriesOfPackage:",
  247. category: 'accessing',
  248. fn: function (aPackage){
  249. var self=this;
  250. var name,map,result;
  251. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  252. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  253. function $MethodCategory(){return smalltalk.MethodCategory||(typeof MethodCategory=="undefined"?nil:MethodCategory)}
  254. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  255. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  256. return smalltalk.withContext(function($ctx1) {
  257. var $1,$2;
  258. name=_st(aPackage)._name();
  259. result=_st($OrderedCollection())._new();
  260. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  261. return smalltalk.withContext(function($ctx2) {
  262. return _st([each,_st(each)._class()])._do_((function(aClass){
  263. return smalltalk.withContext(function($ctx3) {
  264. map=_st($Dictionary())._new();
  265. map;
  266. _st(aClass)._protocolsDo_((function(category,methods){
  267. return smalltalk.withContext(function($ctx4) {
  268. $1=_st(category)._match_("^\x5c*".__comma(name));
  269. if(smalltalk.assert($1)){
  270. return _st(map)._at_put_(category,methods);
  271. };
  272. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx3)})}));
  273. return _st(result)._addAll_(_st(_st(_st(map)._keys())._sorted_((function(a,b){
  274. return smalltalk.withContext(function($ctx4) {
  275. return _st(a).__lt_eq(b);
  276. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._collect_((function(category){
  277. return smalltalk.withContext(function($ctx4) {
  278. return _st($MethodCategory())._name_theClass_methods_(category,aClass,_st(map)._at_(category));
  279. }, function($ctx4) {$ctx4.fillBlock({category:category},$ctx3)})})));
  280. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  281. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  282. $2=result;
  283. return $2;
  284. }, function($ctx1) {$ctx1.fill(self,"extensionCategoriesOfPackage:",{aPackage:aPackage,name:name,map:map,result:result},smalltalk.ChunkExporter)})},
  285. args: ["aPackage"],
  286. source: "extensionCategoriesOfPackage: aPackage\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map result |\x0a\x09name := aPackage 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\x09MethodCategory name: category theClass: aClass methods: (map at: category)]) ]].\x0a\x09^result",
  287. messageSends: ["name", "new", "do:", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "addAll:", "collect:", "name:theClass:methods:", "at:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  288. referencedClasses: ["OrderedCollection", "Dictionary", "MethodCategory", "Smalltalk", "Package"]
  289. }),
  290. smalltalk.ChunkExporter);
  291. smalltalk.addMethod(
  292. smalltalk.method({
  293. selector: "methodsOfCategory:",
  294. category: 'accessing',
  295. fn: function (aCategory){
  296. var self=this;
  297. return smalltalk.withContext(function($ctx1) {
  298. var $1;
  299. $1=_st(_st(aCategory)._methods())._sorted_((function(a,b){
  300. return smalltalk.withContext(function($ctx2) {
  301. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  302. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})}));
  303. return $1;
  304. }, function($ctx1) {$ctx1.fill(self,"methodsOfCategory:",{aCategory:aCategory},smalltalk.ChunkExporter)})},
  305. args: ["aCategory"],
  306. source: "methodsOfCategory: aCategory\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^(aCategory methods) sorted: [:a :b | a selector <= b selector]",
  307. messageSends: ["sorted:", "<=", "selector", "methods"],
  308. referencedClasses: []
  309. }),
  310. smalltalk.ChunkExporter);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "ownCategoriesOfClass:",
  314. category: 'accessing',
  315. fn: function (aClass){
  316. var self=this;
  317. var map;
  318. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  319. function $MethodCategory(){return smalltalk.MethodCategory||(typeof MethodCategory=="undefined"?nil:MethodCategory)}
  320. return smalltalk.withContext(function($ctx1) {
  321. var $1,$2;
  322. map=_st($Dictionary())._new();
  323. _st(aClass)._protocolsDo_((function(category,methods){
  324. return smalltalk.withContext(function($ctx2) {
  325. $1=_st(category)._match_("^\x5c*");
  326. if(! smalltalk.assert($1)){
  327. return _st(map)._at_put_(category,methods);
  328. };
  329. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  330. $2=_st(_st(_st(map)._keys())._sorted_((function(a,b){
  331. return smalltalk.withContext(function($ctx2) {
  332. return _st(a).__lt_eq(b);
  333. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._collect_((function(category){
  334. return smalltalk.withContext(function($ctx2) {
  335. return _st($MethodCategory())._name_theClass_methods_(category,aClass,_st(map)._at_(category));
  336. }, function($ctx2) {$ctx2.fillBlock({category:category},$ctx1)})}));
  337. return $2;
  338. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfClass:",{aClass:aClass,map:map},smalltalk.ChunkExporter)})},
  339. args: ["aClass"],
  340. source: "ownCategoriesOfClass: aClass\x0a\x09\x22Answer the protocols of aClassthat are not package extensions\x22\x0a\x09\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\x09MethodCategory name: category theClass: aClass methods: (map at: category) ]",
  341. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "collect:", "name:theClass:methods:", "at:", "sorted:", "<=", "keys"],
  342. referencedClasses: ["Dictionary", "MethodCategory"]
  343. }),
  344. smalltalk.ChunkExporter);
  345. smalltalk.addMethod(
  346. smalltalk.method({
  347. selector: "ownCategoriesOfMetaClass:",
  348. category: 'accessing',
  349. fn: function (aClass){
  350. var self=this;
  351. return smalltalk.withContext(function($ctx1) {
  352. var $1;
  353. $1=self._ownCategoriesOfClass_(_st(aClass)._class());
  354. return $1;
  355. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfMetaClass:",{aClass:aClass},smalltalk.ChunkExporter)})},
  356. args: ["aClass"],
  357. source: "ownCategoriesOfMetaClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09^self ownCategoriesOfClass: aClass class",
  358. messageSends: ["ownCategoriesOfClass:", "class"],
  359. referencedClasses: []
  360. }),
  361. smalltalk.ChunkExporter);
  362. smalltalk.addMethod(
  363. smalltalk.method({
  364. selector: "recipe",
  365. category: 'fileOut',
  366. fn: function (){
  367. var self=this;
  368. var exportCategoryRecipe;
  369. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1;
  372. exportCategoryRecipe=[self.__minus_gt("exportCategoryPrologueOf:on:"),[self.__minus_gt("methodsOfCategory:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportCategoryEpilogueOf:on:")];
  373. $1=[self.__minus_gt("exportPackageDefinitionOf:on:"),[_st($PluggableExporter()).__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfClass:")]).__comma(exportCategoryRecipe),self.__minus_gt("exportMetaDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfMetaClass:")]).__comma(exportCategoryRecipe)],_st([self.__minus_gt("extensionCategoriesOfPackage:")]).__comma(exportCategoryRecipe)];
  374. return $1;
  375. }, function($ctx1) {$ctx1.fill(self,"recipe",{exportCategoryRecipe:exportCategoryRecipe},smalltalk.ChunkExporter)})},
  376. args: [],
  377. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09| exportCategoryRecipe |\x0a\x09exportCategoryRecipe := {\x0a\x09\x09self -> #exportCategoryPrologueOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09self -> #methodsOfCategory:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportCategoryEpilogueOf:on: }.\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09PluggableExporter -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfClass: }, exportCategoryRecipe.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfMetaClass: }, exportCategoryRecipe }.\x0a\x09\x09{ self -> #extensionCategoriesOfPackage: }, exportCategoryRecipe\x0a\x09}",
  378. messageSends: ["->", ","],
  379. referencedClasses: ["PluggableExporter"]
  380. }),
  381. smalltalk.ChunkExporter);
  382. smalltalk.addClass('Exporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  383. 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.";
  384. smalltalk.addMethod(
  385. smalltalk.method({
  386. selector: "classNameFor:",
  387. category: 'convenience',
  388. fn: function (aClass){
  389. var self=this;
  390. return smalltalk.withContext(function($ctx1) {
  391. var $2,$3,$1;
  392. $2=_st(aClass)._isMetaclass();
  393. if(smalltalk.assert($2)){
  394. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  395. } else {
  396. $3=_st(aClass)._isNil();
  397. if(smalltalk.assert($3)){
  398. $1="nil";
  399. } else {
  400. $1=_st(aClass)._name();
  401. };
  402. };
  403. return $1;
  404. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  405. args: ["aClass"],
  406. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, '.klass' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  407. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  408. referencedClasses: []
  409. }),
  410. smalltalk.Exporter);
  411. smalltalk.addMethod(
  412. smalltalk.method({
  413. selector: "exportDefinitionOf:on:",
  414. category: 'output',
  415. fn: function (aClass,aStream){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) {
  418. var $1,$2,$3,$4,$5,$6,$7;
  419. $1=aStream;
  420. _st($1)._lf();
  421. _st($1)._nextPutAll_("smalltalk.addClass(");
  422. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  423. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  424. $2=_st($1)._nextPutAll_(", [");
  425. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  426. return smalltalk.withContext(function($ctx2) {
  427. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  428. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  429. return smalltalk.withContext(function($ctx2) {
  430. return _st(aStream)._nextPutAll_(", ");
  431. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  432. $3=aStream;
  433. _st($3)._nextPutAll_("], '");
  434. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  435. $4=_st($3)._nextPutAll_(");");
  436. $5=_st(_st(aClass)._comment())._notEmpty();
  437. if(smalltalk.assert($5)){
  438. $6=aStream;
  439. _st($6)._lf();
  440. _st($6)._nextPutAll_("smalltalk.");
  441. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  442. _st($6)._nextPutAll_(".comment=");
  443. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  444. $7=_st($6)._nextPutAll_(";");
  445. $7;
  446. };
  447. _st(aStream)._lf();
  448. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  449. args: ["aClass", "aStream"],
  450. 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",
  451. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  452. referencedClasses: []
  453. }),
  454. smalltalk.Exporter);
  455. smalltalk.addMethod(
  456. smalltalk.method({
  457. selector: "exportMetaDefinitionOf:on:",
  458. category: 'output',
  459. fn: function (aClass,aStream){
  460. var self=this;
  461. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  462. return smalltalk.withContext(function($ctx1) {
  463. var $1,$2,$3;
  464. _st(aStream)._lf();
  465. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  466. if(! smalltalk.assert($1)){
  467. $2=aStream;
  468. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  469. $3=_st($2)._nextPutAll_(".iVarNames = [");
  470. $3;
  471. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  472. return smalltalk.withContext(function($ctx2) {
  473. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  474. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  475. return smalltalk.withContext(function($ctx2) {
  476. return _st(aStream)._nextPutAll_(",");
  477. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  478. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  479. };
  480. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  481. args: ["aClass", "aStream"],
  482. 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]",
  483. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  484. referencedClasses: ["String"]
  485. }),
  486. smalltalk.Exporter);
  487. smalltalk.addMethod(
  488. smalltalk.method({
  489. selector: "exportMethod:on:",
  490. category: 'output',
  491. fn: function (aMethod,aStream){
  492. var self=this;
  493. return smalltalk.withContext(function($ctx1) {
  494. var $1,$2,$3,$4;
  495. $1=aStream;
  496. _st($1)._nextPutAll_("smalltalk.addMethod(");
  497. _st($1)._lf();
  498. _st($1)._nextPutAll_("smalltalk.method({");
  499. _st($1)._lf();
  500. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  501. _st($1)._lf();
  502. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  503. _st($1)._lf();
  504. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  505. _st($1)._lf();
  506. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  507. _st($1)._lf();
  508. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  509. _st($1)._lf();
  510. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  511. _st($1)._lf();
  512. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  513. $3=aStream;
  514. _st($3)._lf();
  515. _st($3)._nextPutAll_("}),");
  516. _st($3)._lf();
  517. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  518. _st($3)._nextPutAll_(");");
  519. _st($3)._lf();
  520. $4=_st($3)._lf();
  521. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter)})},
  522. args: ["aMethod", "aStream"],
  523. 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",
  524. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  525. referencedClasses: []
  526. }),
  527. smalltalk.Exporter);
  528. smalltalk.addMethod(
  529. smalltalk.method({
  530. selector: "exportPackageDefinitionOf:on:",
  531. category: 'output',
  532. fn: function (aPackage,aStream){
  533. var self=this;
  534. return smalltalk.withContext(function($ctx1) {
  535. var $1,$2;
  536. $1=aStream;
  537. _st($1)._nextPutAll_("smalltalk.addPackage(");
  538. _st($1)._nextPutAll_(_st("'".__comma(_st(aPackage)._name())).__comma("');"));
  539. $2=_st($1)._lf();
  540. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  541. args: ["aPackage", "aStream"],
  542. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', aPackage name, ''');';\x0a\x09\x09lf",
  543. messageSends: ["nextPutAll:", ",", "name", "lf"],
  544. referencedClasses: []
  545. }),
  546. smalltalk.Exporter);
  547. smalltalk.addMethod(
  548. smalltalk.method({
  549. selector: "exportPackageEpilogueOf:on:",
  550. category: 'output',
  551. fn: function (aPackage,aStream){
  552. var self=this;
  553. return smalltalk.withContext(function($ctx1) {
  554. var $1,$2;
  555. $1=aStream;
  556. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  557. $2=_st($1)._lf();
  558. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  559. args: ["aPackage", "aStream"],
  560. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  561. messageSends: ["nextPutAll:", "lf"],
  562. referencedClasses: []
  563. }),
  564. smalltalk.Exporter);
  565. smalltalk.addMethod(
  566. smalltalk.method({
  567. selector: "exportPackagePrologueOf:on:",
  568. category: 'output',
  569. fn: function (aPackage,aStream){
  570. var self=this;
  571. return smalltalk.withContext(function($ctx1) {
  572. var $1,$2;
  573. $1=aStream;
  574. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  575. $2=_st($1)._lf();
  576. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  577. args: ["aPackage", "aStream"],
  578. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  579. messageSends: ["nextPutAll:", "lf"],
  580. referencedClasses: []
  581. }),
  582. smalltalk.Exporter);
  583. smalltalk.addMethod(
  584. smalltalk.method({
  585. selector: "extensionMethodsOfPackage:",
  586. category: 'accessing',
  587. fn: function (aPackage){
  588. var self=this;
  589. var name,result;
  590. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  591. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  592. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  593. return smalltalk.withContext(function($ctx1) {
  594. var $1;
  595. name=_st(aPackage)._name();
  596. result=_st($OrderedCollection())._new();
  597. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  598. return smalltalk.withContext(function($ctx2) {
  599. return _st([each,_st(each)._class()])._do_((function(aClass){
  600. return smalltalk.withContext(function($ctx3) {
  601. return _st(result)._addAll_(_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  602. return smalltalk.withContext(function($ctx4) {
  603. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  604. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._select_((function(method){
  605. return smalltalk.withContext(function($ctx4) {
  606. return _st(_st(method)._category())._match_("^\x5c*".__comma(name));
  607. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx3)})})));
  608. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  609. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  610. $1=result;
  611. return $1;
  612. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{aPackage:aPackage,name:name,result:result},smalltalk.Exporter)})},
  613. args: ["aPackage"],
  614. source: "extensionMethodsOfPackage: aPackage\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name result |\x0a\x09name := aPackage 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",
  615. messageSends: ["name", "new", "do:", "addAll:", "select:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  616. referencedClasses: ["OrderedCollection", "Smalltalk", "Package"]
  617. }),
  618. smalltalk.Exporter);
  619. smalltalk.addMethod(
  620. smalltalk.method({
  621. selector: "ownMethodsOfClass:",
  622. category: 'accessing',
  623. fn: function (aClass){
  624. var self=this;
  625. return smalltalk.withContext(function($ctx1) {
  626. var $1;
  627. $1=_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  628. return smalltalk.withContext(function($ctx2) {
  629. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  630. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._reject_((function(each){
  631. return smalltalk.withContext(function($ctx2) {
  632. return _st(_st(each)._category())._match_("^\x5c*");
  633. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  634. return $1;
  635. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfClass:",{aClass:aClass},smalltalk.Exporter)})},
  636. args: ["aClass"],
  637. 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*')]",
  638. messageSends: ["reject:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary"],
  639. referencedClasses: []
  640. }),
  641. smalltalk.Exporter);
  642. smalltalk.addMethod(
  643. smalltalk.method({
  644. selector: "ownMethodsOfMetaClass:",
  645. category: 'accessing',
  646. fn: function (aClass){
  647. var self=this;
  648. return smalltalk.withContext(function($ctx1) {
  649. var $1;
  650. $1=self._ownMethodsOfClass_(_st(aClass)._class());
  651. return $1;
  652. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfMetaClass:",{aClass:aClass},smalltalk.Exporter)})},
  653. args: ["aClass"],
  654. source: "ownMethodsOfMetaClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^self ownMethodsOfClass: aClass class",
  655. messageSends: ["ownMethodsOfClass:", "class"],
  656. referencedClasses: []
  657. }),
  658. smalltalk.Exporter);
  659. smalltalk.addMethod(
  660. smalltalk.method({
  661. selector: "recipe",
  662. category: 'fileOut',
  663. fn: function (){
  664. var self=this;
  665. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  666. return smalltalk.withContext(function($ctx1) {
  667. var $1;
  668. $1=[self.__minus_gt("exportPackagePrologueOf:on:"),self.__minus_gt("exportPackageDefinitionOf:on:"),[_st($PluggableExporter()).__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfClass:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportMetaDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfMetaClass:"),self.__minus_gt("exportMethod:on:")]],[self.__minus_gt("extensionMethodsOfPackage:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportPackageEpilogueOf:on:")];
  669. return $1;
  670. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.Exporter)})},
  671. args: [],
  672. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackagePrologueOf:on:.\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09PluggableExporter -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfMetaClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: } }.\x0a\x09\x09{\x0a\x09\x09\x09self -> #extensionMethodsOfPackage:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportPackageEpilogueOf:on:\x0a\x09}",
  673. messageSends: ["->"],
  674. referencedClasses: ["PluggableExporter"]
  675. }),
  676. smalltalk.Exporter);
  677. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  678. smalltalk.StrippedExporter.comment="I export Amber code into a JavaScript string, but without any optional associated data like the Amber source code.";
  679. smalltalk.addMethod(
  680. smalltalk.method({
  681. selector: "exportDefinitionOf:on:",
  682. category: 'output',
  683. fn: function (aClass,aStream){
  684. var self=this;
  685. return smalltalk.withContext(function($ctx1) {
  686. var $1,$2,$3,$4;
  687. $1=aStream;
  688. _st($1)._lf();
  689. _st($1)._nextPutAll_("smalltalk.addClass(");
  690. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  691. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  692. $2=_st($1)._nextPutAll_(", [");
  693. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  694. return smalltalk.withContext(function($ctx2) {
  695. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  696. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  697. return smalltalk.withContext(function($ctx2) {
  698. return _st(aStream)._nextPutAll_(", ");
  699. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  700. $3=aStream;
  701. _st($3)._nextPutAll_("], '");
  702. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  703. $4=_st($3)._nextPutAll_(");");
  704. _st(aStream)._lf();
  705. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  706. args: ["aClass", "aStream"],
  707. 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",
  708. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category"],
  709. referencedClasses: []
  710. }),
  711. smalltalk.StrippedExporter);
  712. smalltalk.addMethod(
  713. smalltalk.method({
  714. selector: "exportMethod:on:",
  715. category: 'output',
  716. fn: function (aMethod,aStream){
  717. var self=this;
  718. return smalltalk.withContext(function($ctx1) {
  719. var $1,$2;
  720. $1=aStream;
  721. _st($1)._nextPutAll_("smalltalk.addMethod(");
  722. _st($1)._lf();
  723. _st($1)._nextPutAll_("smalltalk.method({");
  724. _st($1)._lf();
  725. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  726. _st($1)._lf();
  727. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  728. _st($1)._lf();
  729. _st($1)._nextPutAll_("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  730. _st($1)._nextPutAll_("}),");
  731. _st($1)._lf();
  732. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  733. _st($1)._nextPutAll_(");");
  734. _st($1)._lf();
  735. $2=_st($1)._lf();
  736. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.StrippedExporter)})},
  737. args: ["aMethod", "aStream"],
  738. 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",
  739. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:", "methodClass"],
  740. referencedClasses: []
  741. }),
  742. smalltalk.StrippedExporter);
  743. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  744. 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";
  745. smalltalk.addMethod(
  746. smalltalk.method({
  747. selector: "nextChunk",
  748. category: 'reading',
  749. fn: function (){
  750. var self=this;
  751. var char,result,chunk;
  752. return smalltalk.withContext(function($ctx1) {
  753. var $1,$2,$3;
  754. var $early={};
  755. try {
  756. result=""._writeStream();
  757. _st((function(){
  758. return smalltalk.withContext(function($ctx2) {
  759. char=_st(self["@stream"])._next();
  760. char;
  761. return _st(char)._notNil();
  762. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  763. return smalltalk.withContext(function($ctx2) {
  764. $1=_st(char).__eq("!");
  765. if(smalltalk.assert($1)){
  766. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  767. if(smalltalk.assert($2)){
  768. _st(self["@stream"])._next();
  769. } else {
  770. $3=_st(_st(result)._contents())._trimBoth();
  771. throw $early=[$3];
  772. };
  773. };
  774. return _st(result)._nextPut_(char);
  775. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  776. return nil;
  777. }
  778. catch(e) {if(e===$early)return e[0]; throw e}
  779. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  780. args: [],
  781. 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",
  782. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  783. referencedClasses: []
  784. }),
  785. smalltalk.ChunkParser);
  786. smalltalk.addMethod(
  787. smalltalk.method({
  788. selector: "stream:",
  789. category: 'accessing',
  790. fn: function (aStream){
  791. var self=this;
  792. return smalltalk.withContext(function($ctx1) {
  793. self["@stream"]=aStream;
  794. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  795. args: ["aStream"],
  796. source: "stream: aStream\x0a\x09stream := aStream",
  797. messageSends: [],
  798. referencedClasses: []
  799. }),
  800. smalltalk.ChunkParser);
  801. smalltalk.addMethod(
  802. smalltalk.method({
  803. selector: "on:",
  804. category: 'not yet classified',
  805. fn: function (aStream){
  806. var self=this;
  807. return smalltalk.withContext(function($ctx1) {
  808. var $1;
  809. $1=_st(self._new())._stream_(aStream);
  810. return $1;
  811. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  812. args: ["aStream"],
  813. source: "on: aStream\x0a\x09^self new stream: aStream",
  814. messageSends: ["stream:", "new"],
  815. referencedClasses: []
  816. }),
  817. smalltalk.ChunkParser.klass);
  818. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  819. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  820. smalltalk.addMethod(
  821. smalltalk.method({
  822. selector: "import:",
  823. category: 'fileIn',
  824. fn: function (aStream){
  825. var self=this;
  826. var chunk,result,parser,lastEmpty;
  827. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  828. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  829. return smalltalk.withContext(function($ctx1) {
  830. var $1,$2;
  831. parser=_st($ChunkParser())._on_(aStream);
  832. lastEmpty=false;
  833. _st((function(){
  834. return smalltalk.withContext(function($ctx2) {
  835. chunk=_st(parser)._nextChunk();
  836. chunk;
  837. return _st(chunk)._isNil();
  838. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  839. return smalltalk.withContext(function($ctx2) {
  840. $1=_st(chunk)._isEmpty();
  841. if(smalltalk.assert($1)){
  842. lastEmpty=true;
  843. return lastEmpty;
  844. } else {
  845. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  846. result;
  847. $2=lastEmpty;
  848. if(smalltalk.assert($2)){
  849. lastEmpty=false;
  850. lastEmpty;
  851. return _st(result)._scanFrom_(parser);
  852. };
  853. };
  854. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  855. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  856. args: ["aStream"],
  857. 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]]]",
  858. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  859. referencedClasses: ["ChunkParser", "Compiler"]
  860. }),
  861. smalltalk.Importer);
  862. smalltalk.addClass('MethodCategory', smalltalk.Object, ['methods', 'name', 'theClass'], 'Importer-Exporter');
  863. smalltalk.MethodCategory.comment="I am an abstraction for a method category in a class / metaclass.\x0a\x0aI know of my class, name and methods.\x0aI am used when exporting a package.";
  864. smalltalk.addMethod(
  865. smalltalk.method({
  866. selector: "methods",
  867. category: 'accessing',
  868. fn: function (){
  869. var self=this;
  870. return smalltalk.withContext(function($ctx1) {
  871. var $1;
  872. $1=self["@methods"];
  873. return $1;
  874. }, function($ctx1) {$ctx1.fill(self,"methods",{},smalltalk.MethodCategory)})},
  875. args: [],
  876. source: "methods\x0a\x09^methods",
  877. messageSends: [],
  878. referencedClasses: []
  879. }),
  880. smalltalk.MethodCategory);
  881. smalltalk.addMethod(
  882. smalltalk.method({
  883. selector: "methods:",
  884. category: 'accessing',
  885. fn: function (aCollection){
  886. var self=this;
  887. return smalltalk.withContext(function($ctx1) {
  888. self["@methods"]=aCollection;
  889. return self}, function($ctx1) {$ctx1.fill(self,"methods:",{aCollection:aCollection},smalltalk.MethodCategory)})},
  890. args: ["aCollection"],
  891. source: "methods: aCollection\x0a\x09methods := aCollection",
  892. messageSends: [],
  893. referencedClasses: []
  894. }),
  895. smalltalk.MethodCategory);
  896. smalltalk.addMethod(
  897. smalltalk.method({
  898. selector: "name",
  899. category: 'accessing',
  900. fn: function (){
  901. var self=this;
  902. return smalltalk.withContext(function($ctx1) {
  903. var $1;
  904. $1=self["@name"];
  905. return $1;
  906. }, function($ctx1) {$ctx1.fill(self,"name",{},smalltalk.MethodCategory)})},
  907. args: [],
  908. source: "name\x0a\x09^name",
  909. messageSends: [],
  910. referencedClasses: []
  911. }),
  912. smalltalk.MethodCategory);
  913. smalltalk.addMethod(
  914. smalltalk.method({
  915. selector: "name:",
  916. category: 'accessing',
  917. fn: function (aString){
  918. var self=this;
  919. return smalltalk.withContext(function($ctx1) {
  920. self["@name"]=aString;
  921. return self}, function($ctx1) {$ctx1.fill(self,"name:",{aString:aString},smalltalk.MethodCategory)})},
  922. args: ["aString"],
  923. source: "name: aString\x0a\x09name := aString",
  924. messageSends: [],
  925. referencedClasses: []
  926. }),
  927. smalltalk.MethodCategory);
  928. smalltalk.addMethod(
  929. smalltalk.method({
  930. selector: "theClass",
  931. category: 'accessing',
  932. fn: function (){
  933. var self=this;
  934. return smalltalk.withContext(function($ctx1) {
  935. var $1;
  936. $1=self["@theClass"];
  937. return $1;
  938. }, function($ctx1) {$ctx1.fill(self,"theClass",{},smalltalk.MethodCategory)})},
  939. args: [],
  940. source: "theClass\x0a\x09^theClass",
  941. messageSends: [],
  942. referencedClasses: []
  943. }),
  944. smalltalk.MethodCategory);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "theClass:",
  948. category: 'accessing',
  949. fn: function (aClass){
  950. var self=this;
  951. return smalltalk.withContext(function($ctx1) {
  952. self["@theClass"]=aClass;
  953. return self}, function($ctx1) {$ctx1.fill(self,"theClass:",{aClass:aClass},smalltalk.MethodCategory)})},
  954. args: ["aClass"],
  955. source: "theClass: aClass\x0a\x09theClass := aClass",
  956. messageSends: [],
  957. referencedClasses: []
  958. }),
  959. smalltalk.MethodCategory);
  960. smalltalk.addMethod(
  961. smalltalk.method({
  962. selector: "name:theClass:methods:",
  963. category: 'not yet classified',
  964. fn: function (aString,aClass,anArray){
  965. var self=this;
  966. return smalltalk.withContext(function($ctx1) {
  967. var $2,$3,$1;
  968. $2=self._new();
  969. _st($2)._name_(aString);
  970. _st($2)._theClass_(aClass);
  971. _st($2)._methods_(anArray);
  972. $3=_st($2)._yourself();
  973. $1=$3;
  974. return $1;
  975. }, function($ctx1) {$ctx1.fill(self,"name:theClass:methods:",{aString:aString,aClass:aClass,anArray:anArray},smalltalk.MethodCategory.klass)})},
  976. args: ["aString", "aClass", "anArray"],
  977. source: "name: aString theClass: aClass methods: anArray\x0a\x09^self new\x0a\x09\x09name: aString;\x0a\x09\x09theClass: aClass;\x0a\x09\x09methods: anArray;\x0a\x09\x09yourself",
  978. messageSends: ["name:", "new", "theClass:", "methods:", "yourself"],
  979. referencedClasses: []
  980. }),
  981. smalltalk.MethodCategory.klass);
  982. smalltalk.addClass('PackageHandler', smalltalk.InterfacingObject, [], 'Importer-Exporter');
  983. 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.";
  984. smalltalk.addMethod(
  985. smalltalk.method({
  986. selector: "ajaxPutAt:data:",
  987. category: 'private',
  988. fn: function (aURL,aString){
  989. var self=this;
  990. return smalltalk.withContext(function($ctx1) {
  991. self._ajax_(smalltalk.HashedCollection._from_(["url".__minus_gt(aURL),"type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  992. return smalltalk.withContext(function($ctx2) {
  993. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  994. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  995. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  996. args: ["aURL", "aString"],
  997. source: "ajaxPutAt: aURL data: aString\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> aURL.\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'] }",
  998. messageSends: ["ajax:", "->", "error:", ",", "responseText"],
  999. referencedClasses: []
  1000. }),
  1001. smalltalk.PackageHandler);
  1002. smalltalk.addMethod(
  1003. smalltalk.method({
  1004. selector: "commit:",
  1005. category: 'committing',
  1006. fn: function (aPackage){
  1007. var self=this;
  1008. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  1009. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1010. return smalltalk.withContext(function($ctx1) {
  1011. _st(self._commitChannels())._do_displayingProgress_((function(commitStrategyFactory){
  1012. var fileContents,commitStrategy;
  1013. return smalltalk.withContext(function($ctx2) {
  1014. commitStrategy=_st(commitStrategyFactory)._value_(aPackage);
  1015. commitStrategy;
  1016. fileContents=_st($String())._streamContents_((function(stream){
  1017. return smalltalk.withContext(function($ctx3) {
  1018. return _st(_st($PluggableExporter())._forRecipe_(_st(commitStrategy)._key()))._exportPackage_on_(aPackage,stream);
  1019. }, function($ctx3) {$ctx3.fillBlock({stream:stream},$ctx2)})}));
  1020. fileContents;
  1021. return self._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  1022. }, function($ctx2) {$ctx2.fillBlock({commitStrategyFactory:commitStrategyFactory,fileContents:fileContents,commitStrategy:commitStrategy},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  1023. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1024. args: ["aPackage"],
  1025. source: "commit: aPackage\x0a\x09self commitChannels\x0a\x09\x09do: [ :commitStrategyFactory || fileContents commitStrategy |\x0a\x09\x09\x09commitStrategy := commitStrategyFactory value: aPackage.\x0a\x09\x09\x09fileContents := String streamContents: [ :stream |\x0a\x09\x09\x09\x09(PluggableExporter forRecipe: commitStrategy key) exportPackage: aPackage on: stream ].\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  1026. messageSends: ["do:displayingProgress:", "value:", "streamContents:", "exportPackage:on:", "forRecipe:", "key", "ajaxPutAt:data:", "value", ",", "name", "commitChannels"],
  1027. referencedClasses: ["PluggableExporter", "String"]
  1028. }),
  1029. smalltalk.PackageHandler);
  1030. smalltalk.addMethod(
  1031. smalltalk.method({
  1032. selector: "commitChannels",
  1033. category: 'committing',
  1034. fn: function (){
  1035. var self=this;
  1036. return smalltalk.withContext(function($ctx1) {
  1037. self._subclassResponsibility();
  1038. return self}, function($ctx1) {$ctx1.fill(self,"commitChannels",{},smalltalk.PackageHandler)})},
  1039. args: [],
  1040. source: "commitChannels\x0a\x09self subclassResponsibility",
  1041. messageSends: ["subclassResponsibility"],
  1042. referencedClasses: []
  1043. }),
  1044. smalltalk.PackageHandler);
  1045. smalltalk.PackageHandler.klass.iVarNames = ['registry'];
  1046. smalltalk.addMethod(
  1047. smalltalk.method({
  1048. selector: "classRegisteredFor:",
  1049. category: 'accessing',
  1050. fn: function (aString){
  1051. var self=this;
  1052. return smalltalk.withContext(function($ctx1) {
  1053. var $1;
  1054. $1=_st(self["@registry"])._at_(aString);
  1055. return $1;
  1056. }, function($ctx1) {$ctx1.fill(self,"classRegisteredFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1057. args: ["aString"],
  1058. source: "classRegisteredFor: aString\x0a\x09^registry at: aString",
  1059. messageSends: ["at:"],
  1060. referencedClasses: []
  1061. }),
  1062. smalltalk.PackageHandler.klass);
  1063. smalltalk.addMethod(
  1064. smalltalk.method({
  1065. selector: "for:",
  1066. category: 'accessing',
  1067. fn: function (aString){
  1068. var self=this;
  1069. return smalltalk.withContext(function($ctx1) {
  1070. var $1;
  1071. $1=_st(self._classRegisteredFor_(aString))._new();
  1072. return $1;
  1073. }, function($ctx1) {$ctx1.fill(self,"for:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1074. args: ["aString"],
  1075. source: "for: aString\x0a\x09^(self classRegisteredFor: aString) new",
  1076. messageSends: ["new", "classRegisteredFor:"],
  1077. referencedClasses: []
  1078. }),
  1079. smalltalk.PackageHandler.klass);
  1080. smalltalk.addMethod(
  1081. smalltalk.method({
  1082. selector: "initialize",
  1083. category: 'initialization',
  1084. fn: function (){
  1085. var self=this;
  1086. return smalltalk.withContext(function($ctx1) {
  1087. smalltalk.PackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1088. self["@registry"]=smalltalk.HashedCollection._from_([]);
  1089. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.PackageHandler.klass)})},
  1090. args: [],
  1091. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}",
  1092. messageSends: ["initialize"],
  1093. referencedClasses: []
  1094. }),
  1095. smalltalk.PackageHandler.klass);
  1096. smalltalk.addMethod(
  1097. smalltalk.method({
  1098. selector: "register:for:",
  1099. category: 'registry',
  1100. fn: function (aClass,aString){
  1101. var self=this;
  1102. return smalltalk.withContext(function($ctx1) {
  1103. _st(self["@registry"])._at_put_(aString,aClass);
  1104. return self}, function($ctx1) {$ctx1.fill(self,"register:for:",{aClass:aClass,aString:aString},smalltalk.PackageHandler.klass)})},
  1105. args: ["aClass", "aString"],
  1106. source: "register: aClass for: aString\x0a\x09registry at: aString put: aClass",
  1107. messageSends: ["at:put:"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.PackageHandler.klass);
  1111. smalltalk.addMethod(
  1112. smalltalk.method({
  1113. selector: "registerFor:",
  1114. category: 'registry',
  1115. fn: function (aString){
  1116. var self=this;
  1117. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1118. return smalltalk.withContext(function($ctx1) {
  1119. _st($PackageHandler())._register_for_(self,aString);
  1120. return self}, function($ctx1) {$ctx1.fill(self,"registerFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1121. args: ["aString"],
  1122. source: "registerFor: aString\x0a\x09PackageHandler register: self for: aString",
  1123. messageSends: ["register:for:"],
  1124. referencedClasses: ["PackageHandler"]
  1125. }),
  1126. smalltalk.PackageHandler.klass);
  1127. smalltalk.addClass('LegacyPackageHandler', smalltalk.PackageHandler, [], 'Importer-Exporter');
  1128. smalltalk.LegacyPackageHandler.comment="I am responsible for handling package loading and committing.\x0d\x0a\x0d\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  1129. smalltalk.addMethod(
  1130. smalltalk.method({
  1131. selector: "commitChannels",
  1132. category: 'committing',
  1133. fn: function (){
  1134. var self=this;
  1135. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  1136. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  1137. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  1138. return smalltalk.withContext(function($ctx1) {
  1139. var $1;
  1140. $1=[(function(pkg){
  1141. return smalltalk.withContext(function($ctx2) {
  1142. return _st(_st(_st($Exporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathJs()).__comma("/")).__comma(_st(pkg)._name())).__comma(".js"));
  1143. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})}),(function(pkg){
  1144. return smalltalk.withContext(function($ctx2) {
  1145. return _st(_st(_st($StrippedExporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathJs()).__comma("/")).__comma(_st(pkg)._name())).__comma(".deploy.js"));
  1146. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})}),(function(pkg){
  1147. return smalltalk.withContext(function($ctx2) {
  1148. return _st(_st(_st($ChunkExporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathSt()).__comma("/")).__comma(_st(pkg)._name())).__comma(".st"));
  1149. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})})];
  1150. return $1;
  1151. }, function($ctx1) {$ctx1.fill(self,"commitChannels",{},smalltalk.LegacyPackageHandler)})},
  1152. args: [],
  1153. source: "commitChannels\x0a\x09^{ \x0a\x09\x09[ :pkg | Exporter default recipe -> (pkg commitPathJs, '/', pkg name, '.js') ].\x0a\x09\x09[ :pkg | StrippedExporter default recipe -> (pkg commitPathJs, '/', pkg name, '.deploy.js') ].\x0a\x09\x09[ :pkg | ChunkExporter default recipe -> (pkg commitPathSt, '/', pkg name, '.st') ]\x0a\x09}",
  1154. messageSends: ["->", ",", "name", "commitPathJs", "recipe", "default", "commitPathSt"],
  1155. referencedClasses: ["Exporter", "StrippedExporter", "ChunkExporter"]
  1156. }),
  1157. smalltalk.LegacyPackageHandler);
  1158. smalltalk.addMethod(
  1159. smalltalk.method({
  1160. selector: "commitPathJsFor:",
  1161. category: 'committing',
  1162. fn: function (aPackage){
  1163. var self=this;
  1164. return smalltalk.withContext(function($ctx1) {
  1165. var $1;
  1166. $1=_st(self._class())._defaultCommitPathJs();
  1167. return $1;
  1168. }, function($ctx1) {$ctx1.fill(self,"commitPathJsFor:",{aPackage:aPackage},smalltalk.LegacyPackageHandler)})},
  1169. args: ["aPackage"],
  1170. source: "commitPathJsFor: aPackage\x0a\x09^self class defaultCommitPathJs",
  1171. messageSends: ["defaultCommitPathJs", "class"],
  1172. referencedClasses: []
  1173. }),
  1174. smalltalk.LegacyPackageHandler);
  1175. smalltalk.addMethod(
  1176. smalltalk.method({
  1177. selector: "commitPathStFor:",
  1178. category: 'committing',
  1179. fn: function (aPackage){
  1180. var self=this;
  1181. return smalltalk.withContext(function($ctx1) {
  1182. var $1;
  1183. $1=_st(self._class())._defaultCommitPathSt();
  1184. return $1;
  1185. }, function($ctx1) {$ctx1.fill(self,"commitPathStFor:",{aPackage:aPackage},smalltalk.LegacyPackageHandler)})},
  1186. args: ["aPackage"],
  1187. source: "commitPathStFor: aPackage\x0a\x09^self class defaultCommitPathSt",
  1188. messageSends: ["defaultCommitPathSt", "class"],
  1189. referencedClasses: []
  1190. }),
  1191. smalltalk.LegacyPackageHandler);
  1192. smalltalk.addMethod(
  1193. smalltalk.method({
  1194. selector: "loadPackage:prefix:",
  1195. category: 'loading',
  1196. fn: function (packageName,aString){
  1197. var self=this;
  1198. var url;
  1199. return smalltalk.withContext(function($ctx1) {
  1200. var $1;
  1201. url=_st(_st(_st("/".__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  1202. self._ajax_(smalltalk.HashedCollection._from_(["url".__minus_gt(url),"type".__minus_gt("GET"),"dataType".__minus_gt("script"),"complete".__minus_gt((function(jqXHR,textStatus){
  1203. return smalltalk.withContext(function($ctx2) {
  1204. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  1205. if(smalltalk.assert($1)){
  1206. return self._setupPackageNamed_prefix_(packageName,aString);
  1207. };
  1208. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),"error".__minus_gt((function(){
  1209. return smalltalk.withContext(function($ctx2) {
  1210. return self._alert_("Could not load package at: ".__comma(url));
  1211. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  1212. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.LegacyPackageHandler)})},
  1213. args: ["packageName", "aString"],
  1214. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> url.\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' -> [ self alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  1215. messageSends: [",", "ajax:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  1216. referencedClasses: []
  1217. }),
  1218. smalltalk.LegacyPackageHandler);
  1219. smalltalk.addMethod(
  1220. smalltalk.method({
  1221. selector: "loadPackages:prefix:",
  1222. category: 'loading',
  1223. fn: function (aCollection,aString){
  1224. var self=this;
  1225. return smalltalk.withContext(function($ctx1) {
  1226. _st(aCollection)._do_((function(each){
  1227. return smalltalk.withContext(function($ctx2) {
  1228. return self._loadPackage_prefix_(each,aString);
  1229. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1230. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.LegacyPackageHandler)})},
  1231. args: ["aCollection", "aString"],
  1232. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  1233. messageSends: ["do:", "loadPackage:prefix:"],
  1234. referencedClasses: []
  1235. }),
  1236. smalltalk.LegacyPackageHandler);
  1237. smalltalk.addMethod(
  1238. smalltalk.method({
  1239. selector: "setupPackageNamed:prefix:",
  1240. category: 'private',
  1241. fn: function (packageName,aString){
  1242. var self=this;
  1243. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  1244. return smalltalk.withContext(function($ctx1) {
  1245. var $1,$2;
  1246. $1=_st($Package())._named_(packageName);
  1247. _st($1)._setupClasses();
  1248. _st($1)._commitPathJs_(_st("/".__comma(aString)).__comma("/js"));
  1249. $2=_st($1)._commitPathSt_(_st("/".__comma(aString)).__comma("/st"));
  1250. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.LegacyPackageHandler)})},
  1251. args: ["packageName", "aString"],
  1252. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  1253. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  1254. referencedClasses: ["Package"]
  1255. }),
  1256. smalltalk.LegacyPackageHandler);
  1257. smalltalk.LegacyPackageHandler.klass.iVarNames = ['defaultCommitPathJs','defaultCommitPathSt'];
  1258. smalltalk.addMethod(
  1259. smalltalk.method({
  1260. selector: "commitPathsFromLoader",
  1261. category: 'commit paths',
  1262. fn: function (){
  1263. var self=this;
  1264. return smalltalk.withContext(function($ctx1) {
  1265. var commitPath = typeof amber !== 'undefined' && amber.commitPath;
  1266. if (!commitPath) return;
  1267. if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);
  1268. if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);
  1269. ;
  1270. return self}, function($ctx1) {$ctx1.fill(self,"commitPathsFromLoader",{},smalltalk.LegacyPackageHandler.klass)})},
  1271. args: [],
  1272. source: "commitPathsFromLoader\x0a\x09<\x0a\x09\x09var commitPath = typeof amber !== 'undefined' && amber.commitPath;\x0a\x09\x09if (!commitPath) return;\x0a\x09\x09if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);\x0a\x09\x09if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);\x0a\x09>",
  1273. messageSends: [],
  1274. referencedClasses: []
  1275. }),
  1276. smalltalk.LegacyPackageHandler.klass);
  1277. smalltalk.addMethod(
  1278. smalltalk.method({
  1279. selector: "defaultCommitPathJs",
  1280. category: 'commit paths',
  1281. fn: function (){
  1282. var self=this;
  1283. return smalltalk.withContext(function($ctx1) {
  1284. var $2,$1;
  1285. $2=self["@defaultCommitPathJs"];
  1286. if(($receiver = $2) == nil || $receiver == undefined){
  1287. self["@defaultCommitPathJs"]="js";
  1288. $1=self["@defaultCommitPathJs"];
  1289. } else {
  1290. $1=$2;
  1291. };
  1292. return $1;
  1293. }, function($ctx1) {$ctx1.fill(self,"defaultCommitPathJs",{},smalltalk.LegacyPackageHandler.klass)})},
  1294. args: [],
  1295. source: "defaultCommitPathJs\x0a\x09^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']",
  1296. messageSends: ["ifNil:"],
  1297. referencedClasses: []
  1298. }),
  1299. smalltalk.LegacyPackageHandler.klass);
  1300. smalltalk.addMethod(
  1301. smalltalk.method({
  1302. selector: "defaultCommitPathJs:",
  1303. category: 'commit paths',
  1304. fn: function (aString){
  1305. var self=this;
  1306. return smalltalk.withContext(function($ctx1) {
  1307. self["@defaultCommitPathJs"]=aString;
  1308. return self}, function($ctx1) {$ctx1.fill(self,"defaultCommitPathJs:",{aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1309. args: ["aString"],
  1310. source: "defaultCommitPathJs: aString\x0a\x09defaultCommitPathJs := aString",
  1311. messageSends: [],
  1312. referencedClasses: []
  1313. }),
  1314. smalltalk.LegacyPackageHandler.klass);
  1315. smalltalk.addMethod(
  1316. smalltalk.method({
  1317. selector: "defaultCommitPathSt",
  1318. category: 'commit paths',
  1319. fn: function (){
  1320. var self=this;
  1321. return smalltalk.withContext(function($ctx1) {
  1322. var $2,$1;
  1323. $2=self["@defaultCommitPathSt"];
  1324. if(($receiver = $2) == nil || $receiver == undefined){
  1325. self["@defaultCommitPathSt"]="st";
  1326. $1=self["@defaultCommitPathSt"];
  1327. } else {
  1328. $1=$2;
  1329. };
  1330. return $1;
  1331. }, function($ctx1) {$ctx1.fill(self,"defaultCommitPathSt",{},smalltalk.LegacyPackageHandler.klass)})},
  1332. args: [],
  1333. source: "defaultCommitPathSt\x0a\x09^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']",
  1334. messageSends: ["ifNil:"],
  1335. referencedClasses: []
  1336. }),
  1337. smalltalk.LegacyPackageHandler.klass);
  1338. smalltalk.addMethod(
  1339. smalltalk.method({
  1340. selector: "defaultCommitPathSt:",
  1341. category: 'commit paths',
  1342. fn: function (aString){
  1343. var self=this;
  1344. return smalltalk.withContext(function($ctx1) {
  1345. self["@defaultCommitPathSt"]=aString;
  1346. return self}, function($ctx1) {$ctx1.fill(self,"defaultCommitPathSt:",{aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1347. args: ["aString"],
  1348. source: "defaultCommitPathSt: aString\x0a\x09defaultCommitPathSt := aString",
  1349. messageSends: [],
  1350. referencedClasses: []
  1351. }),
  1352. smalltalk.LegacyPackageHandler.klass);
  1353. smalltalk.addMethod(
  1354. smalltalk.method({
  1355. selector: "initialize",
  1356. category: 'initialization',
  1357. fn: function (){
  1358. var self=this;
  1359. return smalltalk.withContext(function($ctx1) {
  1360. smalltalk.LegacyPackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1361. self._registerFor_("unknown");
  1362. self._commitPathsFromLoader();
  1363. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.LegacyPackageHandler.klass)})},
  1364. args: [],
  1365. source: "initialize\x0a\x09super initialize.\x0a\x09self registerFor: 'unknown'.\x0a\x09self commitPathsFromLoader",
  1366. messageSends: ["initialize", "registerFor:", "commitPathsFromLoader"],
  1367. referencedClasses: []
  1368. }),
  1369. smalltalk.LegacyPackageHandler.klass);
  1370. smalltalk.addMethod(
  1371. smalltalk.method({
  1372. selector: "loadPackages:prefix:",
  1373. category: 'loading',
  1374. fn: function (aCollection,aString){
  1375. var self=this;
  1376. return smalltalk.withContext(function($ctx1) {
  1377. var $1;
  1378. $1=_st(self._new())._loadPackages_prefix_(aCollection,aString);
  1379. return $1;
  1380. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1381. args: ["aCollection", "aString"],
  1382. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  1383. messageSends: ["loadPackages:prefix:", "new"],
  1384. referencedClasses: []
  1385. }),
  1386. smalltalk.LegacyPackageHandler.klass);
  1387. smalltalk.addMethod(
  1388. smalltalk.method({
  1389. selector: "resetCommitPaths",
  1390. category: 'commit paths',
  1391. fn: function (){
  1392. var self=this;
  1393. return smalltalk.withContext(function($ctx1) {
  1394. self["@defaultCommitPathJs"]=nil;
  1395. self["@defaultCommitPathSt"]=nil;
  1396. return self}, function($ctx1) {$ctx1.fill(self,"resetCommitPaths",{},smalltalk.LegacyPackageHandler.klass)})},
  1397. args: [],
  1398. source: "resetCommitPaths\x0a\x09defaultCommitPathJs := nil.\x0a\x09defaultCommitPathSt := nil",
  1399. messageSends: [],
  1400. referencedClasses: []
  1401. }),
  1402. smalltalk.LegacyPackageHandler.klass);
  1403. smalltalk.addClass('PluggableExporter', smalltalk.Object, ['recipe'], 'Importer-Exporter');
  1404. smalltalk.PluggableExporter.comment="I am an engine for exporting structured data on a Stream.\x0a\x0aMy instances are created using\x0a PluggableExporter newUsing: recipe,\x0awhere recipe is structured description of the exporting algorithm.\x0a\x0aThe actual exporting is done by interpreting the recipe using a `RecipeInterpreter`.\x0a\x0a\x0aI am used to export amber packages, so I have a convenience method\x0a`exportPackage: aPackage on: aStream`\x0awhich exports `aPackage` using the `recipe`\x0a(it is otherwise no special, so it may be renamed to export:on:)";
  1405. smalltalk.addMethod(
  1406. smalltalk.method({
  1407. selector: "exportAllPackages",
  1408. category: 'fileOut',
  1409. fn: function (){
  1410. var self=this;
  1411. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1412. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1413. return smalltalk.withContext(function($ctx1) {
  1414. var $1;
  1415. $1=_st($String())._streamContents_((function(stream){
  1416. return smalltalk.withContext(function($ctx2) {
  1417. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  1418. return smalltalk.withContext(function($ctx3) {
  1419. return self._exportPackage_on_(pkg,stream);
  1420. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  1421. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  1422. return $1;
  1423. }, function($ctx1) {$ctx1.fill(self,"exportAllPackages",{},smalltalk.PluggableExporter)})},
  1424. args: [],
  1425. source: "exportAllPackages\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]]",
  1426. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  1427. referencedClasses: ["Smalltalk", "String"]
  1428. }),
  1429. smalltalk.PluggableExporter);
  1430. smalltalk.addMethod(
  1431. smalltalk.method({
  1432. selector: "exportPackage:on:",
  1433. category: 'fileOut',
  1434. fn: function (aPackage,aStream){
  1435. var self=this;
  1436. return smalltalk.withContext(function($ctx1) {
  1437. _st(self._interpreter())._interpret_for_on_(self._recipe(),aPackage,aStream);
  1438. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.PluggableExporter)})},
  1439. args: ["aPackage", "aStream"],
  1440. source: "exportPackage: aPackage on: aStream\x0a\x09self interpreter interpret: self recipe for: aPackage on: aStream",
  1441. messageSends: ["interpret:for:on:", "recipe", "interpreter"],
  1442. referencedClasses: []
  1443. }),
  1444. smalltalk.PluggableExporter);
  1445. smalltalk.addMethod(
  1446. smalltalk.method({
  1447. selector: "interpreter",
  1448. category: 'accessing',
  1449. fn: function (){
  1450. var self=this;
  1451. function $RecipeInterpreter(){return smalltalk.RecipeInterpreter||(typeof RecipeInterpreter=="undefined"?nil:RecipeInterpreter)}
  1452. return smalltalk.withContext(function($ctx1) {
  1453. var $1;
  1454. $1=_st($RecipeInterpreter())._new();
  1455. return $1;
  1456. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.PluggableExporter)})},
  1457. args: [],
  1458. source: "interpreter\x0a\x09^ RecipeInterpreter new",
  1459. messageSends: ["new"],
  1460. referencedClasses: ["RecipeInterpreter"]
  1461. }),
  1462. smalltalk.PluggableExporter);
  1463. smalltalk.addMethod(
  1464. smalltalk.method({
  1465. selector: "recipe",
  1466. category: 'accessing',
  1467. fn: function (){
  1468. var self=this;
  1469. return smalltalk.withContext(function($ctx1) {
  1470. var $1;
  1471. $1=self["@recipe"];
  1472. return $1;
  1473. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.PluggableExporter)})},
  1474. args: [],
  1475. source: "recipe\x0a\x09^recipe",
  1476. messageSends: [],
  1477. referencedClasses: []
  1478. }),
  1479. smalltalk.PluggableExporter);
  1480. smalltalk.addMethod(
  1481. smalltalk.method({
  1482. selector: "recipe:",
  1483. category: 'accessing',
  1484. fn: function (anArray){
  1485. var self=this;
  1486. return smalltalk.withContext(function($ctx1) {
  1487. self["@recipe"]=anArray;
  1488. return self}, function($ctx1) {$ctx1.fill(self,"recipe:",{anArray:anArray},smalltalk.PluggableExporter)})},
  1489. args: ["anArray"],
  1490. source: "recipe: anArray\x0a\x09recipe := anArray",
  1491. messageSends: [],
  1492. referencedClasses: []
  1493. }),
  1494. smalltalk.PluggableExporter);
  1495. smalltalk.addMethod(
  1496. smalltalk.method({
  1497. selector: "forRecipe:",
  1498. category: 'instance creation',
  1499. fn: function (aRecipe){
  1500. var self=this;
  1501. return smalltalk.withContext(function($ctx1) {
  1502. var $2,$3,$1;
  1503. $2=self._new();
  1504. _st($2)._recipe_(aRecipe);
  1505. $3=_st($2)._yourself();
  1506. $1=$3;
  1507. return $1;
  1508. }, function($ctx1) {$ctx1.fill(self,"forRecipe:",{aRecipe:aRecipe},smalltalk.PluggableExporter.klass)})},
  1509. args: ["aRecipe"],
  1510. source: "forRecipe: aRecipe\x0a\x09^self new recipe: aRecipe; yourself",
  1511. messageSends: ["recipe:", "new", "yourself"],
  1512. referencedClasses: []
  1513. }),
  1514. smalltalk.PluggableExporter.klass);
  1515. smalltalk.addMethod(
  1516. smalltalk.method({
  1517. selector: "ownClassesOfPackage:",
  1518. category: 'convenience',
  1519. fn: function (package_){
  1520. var self=this;
  1521. return smalltalk.withContext(function($ctx1) {
  1522. var $1;
  1523. $1=_st(_st(package_)._sortedClasses())._asSet();
  1524. return $1;
  1525. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.PluggableExporter.klass)})},
  1526. args: ["package"],
  1527. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  1528. messageSends: ["asSet", "sortedClasses"],
  1529. referencedClasses: []
  1530. }),
  1531. smalltalk.PluggableExporter.klass);
  1532. smalltalk.addClass('RecipeInterpreter', smalltalk.Object, [], 'Importer-Exporter');
  1533. smalltalk.RecipeInterpreter.comment="I am an interpreter for export recipes.\x0a\x0a## Recipe format\x0a\x0aRecipe is an array, which can contain two kinds of elements:\x0a\x0a - an assocation where the key is the receiver and the value is a two-arguments selector\x0a In this case, `receiver perform: selector withArguments: { data. stream }` is called.\x0a\x09This essentially defines one step of export process.\x0a\x09The key (eg. receiver) is presumed to be some kind of 'repository' of the exporting methods\x0a\x09that just format appropriate aspect of data into a stream; like a class or a singleton,\x0a\x09so that the recipe itself can be decoupled from data.\x0a\x0a - a subarray, where first element is special and the rest is recursive recipe.\x0a\x0a `subarray first` must be an association similar to one above,\x0a\x09with key being the 'repository' receiver, but value is one-arg selector.\x0a\x09In this case, `receiver perform: selector withArguments: { data }` should create a collection.\x0a\x09Then, the sub-recipe (`subarray allButFirst`) is applied to every element of a collection, eg.\x0a\x09 collection do: [ :each | self export: each using: sa allButFirst on: stream ]";
  1534. smalltalk.addMethod(
  1535. smalltalk.method({
  1536. selector: "interpret:for:on:",
  1537. category: 'interpreting',
  1538. fn: function (aRecipe,anObject,aStream){
  1539. var self=this;
  1540. var recipeStream;
  1541. return smalltalk.withContext(function($ctx1) {
  1542. recipeStream=_st(aRecipe)._readStream();
  1543. _st((function(){
  1544. return smalltalk.withContext(function($ctx2) {
  1545. return _st(recipeStream)._atEnd();
  1546. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  1547. return smalltalk.withContext(function($ctx2) {
  1548. return self._interpretStep_for_on_(_st(recipeStream)._next(),anObject,aStream);
  1549. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1550. return self}, function($ctx1) {$ctx1.fill(self,"interpret:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,recipeStream:recipeStream},smalltalk.RecipeInterpreter)})},
  1551. args: ["aRecipe", "anObject", "aStream"],
  1552. source: "interpret: aRecipe for: anObject on: aStream\x0a\x09| recipeStream |\x0a\x09\x0a\x09recipeStream := aRecipe readStream.\x0a\x09\x0a\x09[ recipeStream atEnd ] whileFalse: [\x0a\x09\x09self \x0a\x09\x09\x09interpretStep: recipeStream next\x0a\x09\x09\x09for: anObject\x0a\x09\x09\x09on: aStream ]",
  1553. messageSends: ["readStream", "whileFalse:", "interpretStep:for:on:", "next", "atEnd"],
  1554. referencedClasses: []
  1555. }),
  1556. smalltalk.RecipeInterpreter);
  1557. smalltalk.addMethod(
  1558. smalltalk.method({
  1559. selector: "interpretStep:for:on:",
  1560. category: 'interpreting',
  1561. fn: function (aRecipeStep,anObject,aStream){
  1562. var self=this;
  1563. return smalltalk.withContext(function($ctx1) {
  1564. var $1,$2;
  1565. $1=_st(_st(aRecipeStep)._value()).__eq_eq(aRecipeStep);
  1566. if(smalltalk.assert($1)){
  1567. $2=self._interpretSubRecipe_for_on_(aRecipeStep,anObject,aStream);
  1568. return $2;
  1569. };
  1570. _st(_st(aRecipeStep)._key())._perform_withArguments_(_st(aRecipeStep)._value(),[anObject,aStream]);
  1571. return self}, function($ctx1) {$ctx1.fill(self,"interpretStep:for:on:",{aRecipeStep:aRecipeStep,anObject:anObject,aStream:aStream},smalltalk.RecipeInterpreter)})},
  1572. args: ["aRecipeStep", "anObject", "aStream"],
  1573. source: "interpretStep: aRecipeStep for: anObject on: aStream\x0a\x09aRecipeStep value == aRecipeStep ifTrue: [ \x0a\x09\x09^ self interpretSubRecipe: aRecipeStep for: anObject on: aStream ].\x0a\x09\x09\x09\x0a\x09aRecipeStep key perform: aRecipeStep value withArguments: { anObject. aStream }",
  1574. messageSends: ["ifTrue:", "interpretSubRecipe:for:on:", "==", "value", "perform:withArguments:", "key"],
  1575. referencedClasses: []
  1576. }),
  1577. smalltalk.RecipeInterpreter);
  1578. smalltalk.addMethod(
  1579. smalltalk.method({
  1580. selector: "interpretSubRecipe:for:on:",
  1581. category: 'interpreting',
  1582. fn: function (aRecipe,anObject,aStream){
  1583. var self=this;
  1584. var selection;
  1585. return smalltalk.withContext(function($ctx1) {
  1586. selection=_st(_st(_st(aRecipe)._first())._key())._perform_withArguments_(_st(_st(aRecipe)._first())._value(),[anObject]);
  1587. _st(selection)._do_((function(each){
  1588. return smalltalk.withContext(function($ctx2) {
  1589. return self._interpret_for_on_(_st(aRecipe)._allButFirst(),each,aStream);
  1590. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1591. return self}, function($ctx1) {$ctx1.fill(self,"interpretSubRecipe:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,selection:selection},smalltalk.RecipeInterpreter)})},
  1592. args: ["aRecipe", "anObject", "aStream"],
  1593. source: "interpretSubRecipe: aRecipe for: anObject on: aStream\x0a\x09| selection |\x0a\x09selection := aRecipe first key \x0a\x09\x09perform: aRecipe first value \x0a\x09\x09withArguments: { anObject }.\x0a\x09selection do: [ :each |\x09\x0a\x09\x09self interpret: aRecipe allButFirst for: each on: aStream ]",
  1594. messageSends: ["perform:withArguments:", "value", "first", "key", "do:", "interpret:for:on:", "allButFirst"],
  1595. referencedClasses: []
  1596. }),
  1597. smalltalk.RecipeInterpreter);
  1598. smalltalk.addMethod(
  1599. smalltalk.method({
  1600. selector: "commit",
  1601. category: '*Importer-Exporter',
  1602. fn: function (){
  1603. var self=this;
  1604. return smalltalk.withContext(function($ctx1) {
  1605. var $1;
  1606. $1=_st(self._transport())._commit_(self);
  1607. return $1;
  1608. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1609. args: [],
  1610. source: "commit\x0a\x09^ self transport commit: self",
  1611. messageSends: ["commit:", "transport"],
  1612. referencedClasses: []
  1613. }),
  1614. smalltalk.Package);
  1615. smalltalk.addMethod(
  1616. smalltalk.method({
  1617. selector: "commitPathJs",
  1618. category: '*Importer-Exporter',
  1619. fn: function (){
  1620. var self=this;
  1621. return smalltalk.withContext(function($ctx1) {
  1622. var $3,$2,$1;
  1623. $3=self["@extension"];
  1624. if(($receiver = $3) == nil || $receiver == undefined){
  1625. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1626. $2=self["@extension"];
  1627. } else {
  1628. $2=$3;
  1629. };
  1630. $1=_st($2)._at_ifAbsentPut_("commitPathJs",(function(){
  1631. return smalltalk.withContext(function($ctx2) {
  1632. return _st(self._transport())._commitPathJsFor_(self);
  1633. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1634. return $1;
  1635. }, function($ctx1) {$ctx1.fill(self,"commitPathJs",{},smalltalk.Package)})},
  1636. args: [],
  1637. source: "commitPathJs\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs ifAbsentPut: [self transport commitPathJsFor: self]",
  1638. messageSends: ["at:ifAbsentPut:", "commitPathJsFor:", "transport", "ifNil:"],
  1639. referencedClasses: []
  1640. }),
  1641. smalltalk.Package);
  1642. smalltalk.addMethod(
  1643. smalltalk.method({
  1644. selector: "commitPathJs:",
  1645. category: '*Importer-Exporter',
  1646. fn: function (aString){
  1647. var self=this;
  1648. return smalltalk.withContext(function($ctx1) {
  1649. var $3,$2,$1;
  1650. $3=self["@extension"];
  1651. if(($receiver = $3) == nil || $receiver == undefined){
  1652. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1653. $2=self["@extension"];
  1654. } else {
  1655. $2=$3;
  1656. };
  1657. $1=_st($2)._at_put_("commitPathJs",aString);
  1658. return $1;
  1659. }, function($ctx1) {$ctx1.fill(self,"commitPathJs:",{aString:aString},smalltalk.Package)})},
  1660. args: ["aString"],
  1661. source: "commitPathJs: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs put: aString",
  1662. messageSends: ["at:put:", "ifNil:"],
  1663. referencedClasses: []
  1664. }),
  1665. smalltalk.Package);
  1666. smalltalk.addMethod(
  1667. smalltalk.method({
  1668. selector: "commitPathSt",
  1669. category: '*Importer-Exporter',
  1670. fn: function (){
  1671. var self=this;
  1672. return smalltalk.withContext(function($ctx1) {
  1673. var $3,$2,$1;
  1674. $3=self["@extension"];
  1675. if(($receiver = $3) == nil || $receiver == undefined){
  1676. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1677. $2=self["@extension"];
  1678. } else {
  1679. $2=$3;
  1680. };
  1681. $1=_st($2)._at_ifAbsentPut_("commitPathSt",(function(){
  1682. return smalltalk.withContext(function($ctx2) {
  1683. return _st(self._transport())._commitPathStFor_(self);
  1684. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1685. return $1;
  1686. }, function($ctx1) {$ctx1.fill(self,"commitPathSt",{},smalltalk.Package)})},
  1687. args: [],
  1688. source: "commitPathSt\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt ifAbsentPut: [self transport commitPathStFor: self]",
  1689. messageSends: ["at:ifAbsentPut:", "commitPathStFor:", "transport", "ifNil:"],
  1690. referencedClasses: []
  1691. }),
  1692. smalltalk.Package);
  1693. smalltalk.addMethod(
  1694. smalltalk.method({
  1695. selector: "commitPathSt:",
  1696. category: '*Importer-Exporter',
  1697. fn: function (aString){
  1698. var self=this;
  1699. return smalltalk.withContext(function($ctx1) {
  1700. var $3,$2,$1;
  1701. $3=self["@extension"];
  1702. if(($receiver = $3) == nil || $receiver == undefined){
  1703. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1704. $2=self["@extension"];
  1705. } else {
  1706. $2=$3;
  1707. };
  1708. $1=_st($2)._at_put_("commitPathSt",aString);
  1709. return $1;
  1710. }, function($ctx1) {$ctx1.fill(self,"commitPathSt:",{aString:aString},smalltalk.Package)})},
  1711. args: ["aString"],
  1712. source: "commitPathSt: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt put: aString",
  1713. messageSends: ["at:put:", "ifNil:"],
  1714. referencedClasses: []
  1715. }),
  1716. smalltalk.Package);
  1717. smalltalk.addMethod(
  1718. smalltalk.method({
  1719. selector: "transport",
  1720. category: '*Importer-Exporter',
  1721. fn: function (){
  1722. var self=this;
  1723. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1724. return smalltalk.withContext(function($ctx1) {
  1725. var $1;
  1726. $1=_st($PackageHandler())._for_(self._transportType());
  1727. return $1;
  1728. }, function($ctx1) {$ctx1.fill(self,"transport",{},smalltalk.Package)})},
  1729. args: [],
  1730. source: "transport\x0a\x09^ PackageHandler for: self transportType",
  1731. messageSends: ["for:", "transportType"],
  1732. referencedClasses: ["PackageHandler"]
  1733. }),
  1734. smalltalk.Package);
  1735. smalltalk.addMethod(
  1736. smalltalk.method({
  1737. selector: "transportType",
  1738. category: '*Importer-Exporter',
  1739. fn: function (){
  1740. var self=this;
  1741. return smalltalk.withContext(function($ctx1) {
  1742. return (self.transport && self.transport.type) || 'unknown';;
  1743. return self}, function($ctx1) {$ctx1.fill(self,"transportType",{},smalltalk.Package)})},
  1744. args: [],
  1745. source: "transportType\x0a\x09<return (self.transport && self.transport.type) || 'unknown';>",
  1746. messageSends: [],
  1747. referencedClasses: []
  1748. }),
  1749. smalltalk.Package);
  1750. })(global_smalltalk,global_nil,global__st);