File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -1711,14 +1711,17 @@ const EasyCoder_Core = {
1711
1711
targetValue = `{}` ;
1712
1712
}
1713
1713
// This is object whose property is being set
1714
- let targetJSON = JSON . parse ( targetValue ) ;
1714
+ let targetJSON = targetValue ;
1715
+ if ( program . isJsonString ( targetValue ) ) {
1716
+ targetJSON = JSON . parse ( targetValue ) ;
1717
+ }
1715
1718
// This is the name of the property
1716
1719
const itemName = program . getValue ( command . name ) ;
1717
1720
// This is the value of the property
1718
1721
const itemValue = program . evaluate ( command . value ) ;
1719
1722
let content = itemValue . content ;
1720
1723
if ( itemValue ) {
1721
- if ( content . length >= 2 && [ `[` , `{` ] . includes ( content [ 0 ] ) ) {
1724
+ if ( program . isJsonString ( itemValue . content ) ) {
1722
1725
targetJSON [ itemName ] = JSON . parse ( itemValue . content ) ;
1723
1726
content = JSON . stringify ( targetJSON ) ;
1724
1727
}
Original file line number Diff line number Diff line change @@ -167,6 +167,15 @@ const EasyCoder = {
167
167
return typeof item === `undefined` ;
168
168
} ,
169
169
170
+ isJsonString : function ( str ) {
171
+ try {
172
+ JSON . parse ( str ) ;
173
+ } catch ( e ) {
174
+ return false ;
175
+ }
176
+ return true ;
177
+ } ,
178
+
170
179
runScript : function ( program ) {
171
180
const command = program [ program . pc ] ;
172
181
const script = program . getValue ( command . script ) ;
@@ -227,6 +236,7 @@ const EasyCoder = {
227
236
program . domain = this . domain ;
228
237
program . require = this . require ;
229
238
program . isUndefined = this . isUndefined ;
239
+ program . isJsonString = this . isJsonString ;
230
240
program . checkPlugin = this . checkPlugin ;
231
241
program . getPlugin = this . getPlugin ;
232
242
program . addLocalPlugin = this . addLocalPlugin ;
Original file line number Diff line number Diff line change @@ -2575,10 +2575,10 @@ const EasyCoder_Browser = {
2575
2575
case `selected` :
2576
2576
let arg = compiler . nextToken ( ) ;
2577
2577
if ( [ `index` , `item` ] . includes ( arg ) ) {
2578
- if ( compiler . nextTokenIs ( `in` ) ) {
2578
+ if ( [ `in` , `of` ] . includes ( compiler . nextToken ( ) ) ) {
2579
2579
if ( compiler . nextIsSymbol ( ) ) {
2580
2580
const symbol = compiler . getSymbolRecord ( ) ;
2581
- if ( [ `ul` , `ol` ] . includes ( symbol . keyword ) ) {
2581
+ if ( [ `ul` , `ol` , `select` ] . includes ( symbol . keyword ) ) {
2582
2582
compiler . next ( ) ;
2583
2583
return {
2584
2584
domain : `browser` ,
@@ -2841,9 +2841,10 @@ const EasyCoder_Browser = {
2841
2841
} ;
2842
2842
case `selected` :
2843
2843
symbolRecord = program . getSymbolRecord ( value . symbol ) ;
2844
- element = symbolRecord . value [ symbolRecord . index ] . content ;
2845
- target = document . getElementById ( element ) ;
2846
- content = ( value . arg === `index` ) ? target . selectedIndex : target . options [ target . selectedIndex ] . text ;
2844
+ target = symbolRecord . element [ symbolRecord . index ] ;
2845
+ let selectedIndex = target . selectedIndex ;
2846
+ let selectedText = selectedIndex >= 0 ? target . options [ selectedIndex ] . text : `` ;
2847
+ content = ( value . arg === `index` ) ? selectedIndex : selectedText ;
2847
2848
return {
2848
2849
type : `constant` ,
2849
2850
numeric : false ,
You can’t perform that action at this time.
0 commit comments