|
@@ -779,6 +779,12 @@ source: aString
|
|
|
|
|
|
argVariables
|
|
argVariables
|
|
^argVariables copy
|
|
^argVariables copy
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+safeVariableNameFor: aString
|
|
|
|
+ ^(Smalltalk current reservedWords includes: aString)
|
|
|
|
+ ifTrue: [aString, '_']
|
|
|
|
+ ifFalse: [aString]
|
|
! !
|
|
! !
|
|
|
|
|
|
!Compiler methodsFor: 'compiling'!
|
|
!Compiler methodsFor: 'compiling'!
|
|
@@ -1184,9 +1190,10 @@ visitBlockNode: aNode
|
|
!
|
|
!
|
|
|
|
|
|
visitSequenceNode: aNode
|
|
visitSequenceNode: aNode
|
|
- aNode temps do: [:each |
|
|
|
|
- tempVariables add: each.
|
|
|
|
- stream nextPutAll: 'var ', each, '=nil;'; lf].
|
|
|
|
|
|
+ aNode temps do: [:each || temp |
|
|
|
|
+ temp := self safeVariableNameFor: each.
|
|
|
|
+ tempVariables add: temp.
|
|
|
|
+ stream nextPutAll: 'var ', temp, '=nil;'; lf].
|
|
aNode nodes do: [:each |
|
|
aNode nodes do: [:each |
|
|
self visit: each.
|
|
self visit: each.
|
|
stream nextPutAll: ';']
|
|
stream nextPutAll: ';']
|
|
@@ -1200,9 +1207,10 @@ visitBlockSequenceNode: aNode
|
|
ifTrue: [
|
|
ifTrue: [
|
|
stream nextPutAll: 'return nil;']
|
|
stream nextPutAll: 'return nil;']
|
|
ifFalse: [
|
|
ifFalse: [
|
|
- aNode temps do: [:each |
|
|
|
|
- tempVariables add: each.
|
|
|
|
- stream nextPutAll: 'var ', each, '=nil;'; lf].
|
|
|
|
|
|
+ aNode temps do: [:each | | temp |
|
|
|
|
+ temp := self safeVariableNameFor: each.
|
|
|
|
+ tempVariables add: temp.
|
|
|
|
+ stream nextPutAll: 'var ', temp, '=nil;'; lf].
|
|
index := 0.
|
|
index := 0.
|
|
aNode nodes do: [:each |
|
|
aNode nodes do: [:each |
|
|
index := index + 1.
|
|
index := index + 1.
|
|
@@ -1288,19 +1296,21 @@ visitClassReferenceNode: aNode
|
|
!
|
|
!
|
|
|
|
|
|
visitVariableNode: aNode
|
|
visitVariableNode: aNode
|
|
|
|
+ | varName |
|
|
(self currentClass allInstanceVariableNames includes: aNode value)
|
|
(self currentClass allInstanceVariableNames includes: aNode value)
|
|
ifTrue: [stream nextPutAll: 'self[''@', aNode value, ''']']
|
|
ifTrue: [stream nextPutAll: 'self[''@', aNode value, ''']']
|
|
ifFalse: [
|
|
ifFalse: [
|
|
- (self knownVariables includes: aNode value)
|
|
|
|
|
|
+ varName := self safeVariableNameFor: aNode value.
|
|
|
|
+ (self knownVariables includes: varName)
|
|
ifFalse: [
|
|
ifFalse: [
|
|
unknownVariables add: aNode value.
|
|
unknownVariables add: aNode value.
|
|
aNode assigned
|
|
aNode assigned
|
|
- ifTrue: [stream nextPutAll: aNode value]
|
|
|
|
- ifFalse: [stream nextPutAll: '(typeof ', aNode value, ' == ''undefined'' ? nil : ', aNode value, ')']]
|
|
|
|
|
|
+ ifTrue: [stream nextPutAll: varName]
|
|
|
|
+ ifFalse: [stream nextPutAll: '(typeof ', varName, ' == ''undefined'' ? nil : ', varName, ')']]
|
|
ifTrue: [
|
|
ifTrue: [
|
|
aNode value = 'thisContext'
|
|
aNode value = 'thisContext'
|
|
ifTrue: [stream nextPutAll: '(smalltalk.getThisContext())']
|
|
ifTrue: [stream nextPutAll: '(smalltalk.getThisContext())']
|
|
- ifFalse: [stream nextPutAll:aNode value]]]
|
|
|
|
|
|
+ ifFalse: [stream nextPutAll: varName]]]
|
|
!
|
|
!
|
|
|
|
|
|
visitJSStatementNode: aNode
|
|
visitJSStatementNode: aNode
|