Browse Source

Committing in closure format.

Herbert Vojčík 11 years ago
parent
commit
238d2331a1
3 changed files with 165 additions and 12 deletions
  1. 58 3
      js/Importer-Exporter.deploy.js
  2. 79 4
      js/Importer-Exporter.js
  3. 28 5
      st/Importer-Exporter.st

+ 58 - 3
js/Importer-Exporter.deploy.js

@@ -266,18 +266,25 @@ return smalltalk.withContext(function($ctx1) {
 var $1;
 $1=_st($String())._streamContents_((function(stream){
 return smalltalk.withContext(function($ctx2) {
+self._exportPackagePrologueOn_(stream);
+return _st((function(){
+return smalltalk.withContext(function($ctx3) {
 package_=_st(_st($Smalltalk())._current())._packageAt_(packageName);
 package_;
 self._exportPackageDefinitionOf_on_(package_,stream);
 _st(_st(_st(package_)._sortedClasses())._asSet())._do_((function(each){
-return smalltalk.withContext(function($ctx3) {
+return smalltalk.withContext(function($ctx4) {
 return _st(stream)._nextPutAll_(self._exportClass_(each));
-}, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2)})}));
+}, function($ctx4) {$ctx4.fillBlock({each:each},$ctx3)})}));
 return self._exportPackageExtensionsOf_on_(package_,stream);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}))._ensure_((function(){
+return smalltalk.withContext(function($ctx3) {
+return self._exportPackageEpilogueOn_(stream);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
 }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"exportPackage:",{packageName:packageName,package_:package_},smalltalk.Exporter)})},
-messageSends: ["streamContents:", "packageAt:", "current", "exportPackageDefinitionOf:on:", "do:", "nextPutAll:", "exportClass:", "asSet", "sortedClasses", "exportPackageExtensionsOf:on:"]}),
+messageSends: ["streamContents:", "exportPackagePrologueOn:", "ensure:", "exportPackageEpilogueOn:", "packageAt:", "current", "exportPackageDefinitionOf:on:", "do:", "nextPutAll:", "exportClass:", "asSet", "sortedClasses", "exportPackageExtensionsOf:on:"]}),
 smalltalk.Exporter);
 
 smalltalk.addMethod(
@@ -295,6 +302,20 @@ return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{
 messageSends: ["nextPutAll:", ",", "name", "lf"]}),
 smalltalk.Exporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackageEpilogueOn:",
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+$1=aStream;
+_st($1)._nextPutAll_("})(smalltalk,nil,_st);");
+$2=_st($1)._lf();
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOn:",{aStream:aStream},smalltalk.Exporter)})},
+messageSends: ["nextPutAll:", "lf"]}),
+smalltalk.Exporter);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "exportPackageExtensionsOf:on:",
@@ -326,6 +347,20 @@ return self}, function($ctx1) {$ctx1.fill(self,"exportPackageExtensionsOf:on:",{
 messageSends: ["name", "do:", "ifTrue:", "exportMethod:of:on:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"]}),
 smalltalk.Exporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackagePrologueOn:",
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+$1=aStream;
+_st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
+$2=_st($1)._lf();
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOn:",{aStream:aStream},smalltalk.Exporter)})},
+messageSends: ["nextPutAll:", "lf"]}),
+smalltalk.Exporter);
+
 
 
 smalltalk.addClass('ChunkExporter', smalltalk.Exporter, [], 'Importer-Exporter');
@@ -522,6 +557,16 @@ return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{
 messageSends: ["nextPutAll:", ",", "name", "lf"]}),
 smalltalk.ChunkExporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackageEpilogueOn:",
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOn:",{aStream:aStream},smalltalk.ChunkExporter)})},
+messageSends: []}),
+smalltalk.ChunkExporter);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "exportPackageExtensionsOf:on:",
@@ -563,6 +608,16 @@ return self}, function($ctx1) {$ctx1.fill(self,"exportPackageExtensionsOf:on:",{
 messageSends: ["name", "do:", "new", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "at:", "exportMethods:category:of:on:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"]}),
 smalltalk.ChunkExporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackagePrologueOn:",
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOn:",{aStream:aStream},smalltalk.ChunkExporter)})},
+messageSends: []}),
+smalltalk.ChunkExporter);
+
 
 
 smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');

+ 79 - 4
js/Importer-Exporter.js

@@ -319,20 +319,27 @@ return smalltalk.withContext(function($ctx1) {
 var $1;
 $1=_st($String())._streamContents_((function(stream){
 return smalltalk.withContext(function($ctx2) {
+self._exportPackagePrologueOn_(stream);
+return _st((function(){
+return smalltalk.withContext(function($ctx3) {
 package_=_st(_st($Smalltalk())._current())._packageAt_(packageName);
 package_;
 self._exportPackageDefinitionOf_on_(package_,stream);
 _st(_st(_st(package_)._sortedClasses())._asSet())._do_((function(each){
-return smalltalk.withContext(function($ctx3) {
+return smalltalk.withContext(function($ctx4) {
 return _st(stream)._nextPutAll_(self._exportClass_(each));
-}, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2)})}));
+}, function($ctx4) {$ctx4.fillBlock({each:each},$ctx3)})}));
 return self._exportPackageExtensionsOf_on_(package_,stream);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}))._ensure_((function(){
+return smalltalk.withContext(function($ctx3) {
+return self._exportPackageEpilogueOn_(stream);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
 }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"exportPackage:",{packageName:packageName,package_:package_},smalltalk.Exporter)})},
 args: ["packageName"],
-source: "exportPackage: packageName\x0a\x09\x22Export a given package by name.\x22\x0a\x0a\x09| package |\x0a\x09^String streamContents: [:stream |\x0a\x09\x09\x09\x09package := Smalltalk current packageAt: packageName.\x0a\x09\x09\x09\x09self exportPackageDefinitionOf: package on: stream.\x0a\x0a\x09\x09\x22Export classes in dependency order.\x0a\x09\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09\x09\x09package sortedClasses asSet do: [:each |\x0a\x09\x09\x09\x09\x09\x09stream nextPutAll: (self exportClass: each)].\x0a\x09\x09self exportPackageExtensionsOf: package on: stream]",
-messageSends: ["streamContents:", "packageAt:", "current", "exportPackageDefinitionOf:on:", "do:", "nextPutAll:", "exportClass:", "asSet", "sortedClasses", "exportPackageExtensionsOf:on:"],
+source: "exportPackage: packageName\x0a\x09\x22Export a given package by name.\x22\x0a\x0a\x09| package |\x0a\x09^String streamContents: [:stream |\x0a\x09\x09self exportPackagePrologueOn: stream.\x0a\x09\x09[\x0a\x09\x09\x09package := Smalltalk current packageAt: packageName.\x0a\x09\x09\x09self exportPackageDefinitionOf: package on: stream.\x0a\x0a\x09\x09\x09\x22Export classes in dependency order.\x0a\x09\x09\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09\x09\x09package sortedClasses asSet do: [:each |\x0a\x09\x09\x09\x09\x09\x09stream nextPutAll: (self exportClass: each)].\x0a\x09\x09\x09self exportPackageExtensionsOf: package on: stream\x0a\x09\x09] ensure: [\x0a\x09\x09\x09self exportPackageEpilogueOn: stream\x0a\x09\x09]]",
+messageSends: ["streamContents:", "exportPackagePrologueOn:", "ensure:", "exportPackageEpilogueOn:", "packageAt:", "current", "exportPackageDefinitionOf:on:", "do:", "nextPutAll:", "exportClass:", "asSet", "sortedClasses", "exportPackageExtensionsOf:on:"],
 referencedClasses: ["Smalltalk", "String"]
 }),
 smalltalk.Exporter);
@@ -357,6 +364,25 @@ referencedClasses: []
 }),
 smalltalk.Exporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackageEpilogueOn:",
+category: 'private',
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+$1=aStream;
+_st($1)._nextPutAll_("})(smalltalk,nil,_st);");
+$2=_st($1)._lf();
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOn:",{aStream:aStream},smalltalk.Exporter)})},
+args: ["aStream"],
+source: "exportPackageEpilogueOn: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(smalltalk,nil,_st);';\x0a\x09\x09lf",
+messageSends: ["nextPutAll:", "lf"],
+referencedClasses: []
+}),
+smalltalk.Exporter);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "exportPackageExtensionsOf:on:",
@@ -393,6 +419,25 @@ referencedClasses: ["Smalltalk", "Package"]
 }),
 smalltalk.Exporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackagePrologueOn:",
+category: 'private',
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+$1=aStream;
+_st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
+$2=_st($1)._lf();
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOn:",{aStream:aStream},smalltalk.Exporter)})},
+args: ["aStream"],
+source: "exportPackagePrologueOn: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
+messageSends: ["nextPutAll:", "lf"],
+referencedClasses: []
+}),
+smalltalk.Exporter);
+
 
 
 smalltalk.addClass('ChunkExporter', smalltalk.Exporter, [], 'Importer-Exporter');
@@ -630,6 +675,21 @@ referencedClasses: []
 }),
 smalltalk.ChunkExporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackageEpilogueOn:",
+category: 'private',
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOn:",{aStream:aStream},smalltalk.ChunkExporter)})},
+args: ["aStream"],
+source: "exportPackageEpilogueOn: aStream",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.ChunkExporter);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "exportPackageExtensionsOf:on:",
@@ -676,6 +736,21 @@ referencedClasses: ["Dictionary", "Smalltalk", "Package"]
 }),
 smalltalk.ChunkExporter);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "exportPackagePrologueOn:",
+category: 'private',
+fn: function (aStream){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOn:",{aStream:aStream},smalltalk.ChunkExporter)})},
+args: ["aStream"],
+source: "exportPackagePrologueOn: aStream",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.ChunkExporter);
+
 
 
 smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');

+ 28 - 5
st/Importer-Exporter.st

@@ -89,14 +89,19 @@ exportPackage: packageName
 
 	| package |
 	^String streamContents: [:stream |
-				package := Smalltalk current packageAt: packageName.
-				self exportPackageDefinitionOf: package on: stream.
+		self exportPackagePrologueOn: stream.
+		[
+			package := Smalltalk current packageAt: packageName.
+			self exportPackageDefinitionOf: package on: stream.
 
-		"Export classes in dependency order.
-		Update (issue #171): Remove duplicates for export"
+			"Export classes in dependency order.
+			Update (issue #171): Remove duplicates for export"
 			package sortedClasses asSet do: [:each |
 						stream nextPutAll: (self exportClass: each)].
-		self exportPackageExtensionsOf: package on: stream]
+			self exportPackageExtensionsOf: package on: stream
+		] ensure: [
+			self exportPackageEpilogueOn: stream
+		]]
 ! !
 
 !Exporter methodsFor: 'private'!
@@ -180,6 +185,12 @@ exportPackageDefinitionOf: package on: aStream
 		lf
 !
 
+exportPackageEpilogueOn: aStream
+	aStream
+		nextPutAll: '})(smalltalk,nil,_st);';
+		lf
+!
+
 exportPackageExtensionsOf: package on: aStream
 	"Issue #143: sort classes and methods alphabetically"
 
@@ -190,6 +201,12 @@ exportPackageExtensionsOf: package on: aStream
 			((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector]) do: [:method |
 				(method category match: '^\*', name) ifTrue: [
 					self exportMethod: method of: aClass on: aStream ]]]]
+!
+
+exportPackagePrologueOn: aStream
+	aStream
+		nextPutAll: '(function(smalltalk,nil,_st){';
+		lf
 ! !
 
 Exporter subclass: #ChunkExporter
@@ -291,6 +308,9 @@ exportPackageDefinitionOf: package on: aStream
 		lf
 !
 
+exportPackageEpilogueOn: aStream
+!
+
 exportPackageExtensionsOf: package on: aStream
 	"We need to override this one too since we need to group
 	all methods in a given protocol under a leading methodsFor: chunk
@@ -308,6 +328,9 @@ exportPackageExtensionsOf: package on: aStream
 			(map keys sorted: [:a :b | a <= b ]) do: [:category | | methods |
 				methods := map at: category.
 				self exportMethods: methods category: category of: aClass on: aStream ]]]
+!
+
+exportPackagePrologueOn: aStream
 ! !
 
 Exporter subclass: #StrippedExporter