@@ -156,7 +156,7 @@ namespace pxt.blocks {
156
156
return find ( ( < any > b ) . p ) ;
157
157
158
158
if ( b . type == "variables_get" )
159
- return find ( lookup ( e , escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ) . type ) ;
159
+ return find ( lookup ( e , escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ) . type ) ;
160
160
161
161
if ( ! b . outputConnection ) {
162
162
return ground ( pUnit . type ) ;
@@ -346,12 +346,12 @@ namespace pxt.blocks {
346
346
case "controls_for_of" :
347
347
unionParam ( e , b , "LIST" , ground ( "Array" ) ) ;
348
348
const listTp = returnType ( e , getInputTargetBlock ( b , "LIST" ) ) ;
349
- const elementTp = lookup ( e , escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ) . type ;
349
+ const elementTp = lookup ( e , escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ) . type ;
350
350
genericLink ( listTp , elementTp ) ;
351
351
break ;
352
352
case "variables_set" :
353
353
case "variables_change" :
354
- let x = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
354
+ let x = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
355
355
let p1 = lookup ( e , x ) . type ;
356
356
attachPlaceholderIf ( e , b , "VALUE" ) ;
357
357
let rhs = getInputTargetBlock ( b , "VALUE" ) ;
@@ -685,6 +685,11 @@ namespace pxt.blocks {
685
685
return mkStmt ( mkText ( name + "()" ) ) ;
686
686
}
687
687
688
+ function compileWorkspaceComment ( c : B . WorkspaceComment ) : JsNode {
689
+ const content = c . getContent ( ) ;
690
+ return Helpers . mkMultiComment ( content ) ;
691
+ }
692
+
688
693
function defaultValueForType ( t : Point ) : JsNode {
689
694
if ( t . type == null ) {
690
695
union ( t , ground ( pNumber . type ) ) ;
@@ -906,7 +911,7 @@ namespace pxt.blocks {
906
911
}
907
912
908
913
function compileControlsFor ( e : Environment , b : B . Block , comments : string [ ] ) : JsNode [ ] {
909
- let bVar = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
914
+ let bVar = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
910
915
let bTo = getInputTargetBlock ( b , "TO" ) ;
911
916
let bDo = getInputTargetBlock ( b , "DO" ) ;
912
917
let bBy = getInputTargetBlock ( b , "BY" ) ;
@@ -955,7 +960,7 @@ namespace pxt.blocks {
955
960
}
956
961
957
962
function compileControlsForOf ( e : Environment , b : B . Block , comments : string [ ] ) {
958
- let bVar = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
963
+ let bVar = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
959
964
let bOf = getInputTargetBlock ( b , "LIST" ) ;
960
965
let bDo = getInputTargetBlock ( b , "DO" ) ;
961
966
@@ -1012,7 +1017,7 @@ namespace pxt.blocks {
1012
1017
}
1013
1018
1014
1019
function compileVariableGet ( e : Environment , b : B . Block ) : JsNode {
1015
- let name = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
1020
+ let name = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
1016
1021
let binding = lookup ( e , name ) ;
1017
1022
if ( ! binding . assigned )
1018
1023
binding . assigned = VarUsage . Read ;
@@ -1021,7 +1026,7 @@ namespace pxt.blocks {
1021
1026
}
1022
1027
1023
1028
function compileSet ( e : Environment , b : B . Block , comments : string [ ] ) : JsNode {
1024
- let bVar = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
1029
+ let bVar = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
1025
1030
let bExpr = getInputTargetBlock ( b , "VALUE" ) ;
1026
1031
let binding = lookup ( e , bVar ) ;
1027
1032
let isDef = false
@@ -1041,7 +1046,7 @@ namespace pxt.blocks {
1041
1046
}
1042
1047
1043
1048
function compileChange ( e : Environment , b : B . Block , comments : string [ ] ) : JsNode {
1044
- let bVar = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
1049
+ let bVar = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
1045
1050
let bExpr = getInputTargetBlock ( b , "VALUE" ) ;
1046
1051
let binding = lookup ( e , bVar ) ;
1047
1052
if ( ! binding . assigned )
@@ -1447,7 +1452,7 @@ namespace pxt.blocks {
1447
1452
if ( ! b )
1448
1453
return false ;
1449
1454
else if ( ( b . type == "controls_for" || b . type == "controls_simple_for" || b . type == "controls_for_of" )
1450
- && escapeVarName ( b . getFieldValue ( "VAR" ) , e ) == name )
1455
+ && escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) == name )
1451
1456
return true ;
1452
1457
else if ( isMutatingBlock ( b ) && b . mutation . isDeclaredByMutation ( name ) )
1453
1458
return true ;
@@ -1486,7 +1491,7 @@ namespace pxt.blocks {
1486
1491
// collect local variables.
1487
1492
if ( w ) w . getAllBlocks ( ) . filter ( b => ! b . disabled ) . forEach ( b => {
1488
1493
if ( b . type == "controls_for" || b . type == "controls_simple_for" || b . type == "controls_for_of" ) {
1489
- let x = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
1494
+ let x = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
1490
1495
if ( b . type == "controls_for_of" ) {
1491
1496
trackLocalDeclaration ( x , null ) ;
1492
1497
}
@@ -1518,7 +1523,7 @@ namespace pxt.blocks {
1518
1523
// set block, 1) make sure that the variable is bound, then 2) mark the variable if needed.
1519
1524
if ( w ) w . getAllBlocks ( ) . filter ( b => ! b . disabled ) . forEach ( b => {
1520
1525
if ( b . type == "variables_get" || b . type == "variables_set" || b . type == "variables_change" ) {
1521
- let x = escapeVarName ( b . getFieldValue ( "VAR" ) , e ) ;
1526
+ let x = escapeVarName ( b . getField ( "VAR" ) . getText ( ) , e ) ;
1522
1527
if ( lookup ( e , x ) == null )
1523
1528
e = extend ( e , x , null ) ;
1524
1529
@@ -1608,7 +1613,16 @@ namespace pxt.blocks {
1608
1613
return mkStmt ( mkText ( "let " + b . name + tp + " = " ) , defl )
1609
1614
} ) ;
1610
1615
1611
- return stmtsVariables . concat ( stmtsMain )
1616
+ const allStmts = stmtsVariables . concat ( stmtsMain ) ;
1617
+
1618
+ // compile workspace comments, add them to the top
1619
+ const commentStmts : JsNode [ ] = [ ] ;
1620
+ const topComments = w . getTopComments ( true )
1621
+ topComments . forEach ( c => {
1622
+ append ( commentStmts , compileWorkspaceComment ( c ) . children ) ;
1623
+ } )
1624
+
1625
+ return commentStmts . concat ( allStmts ) ;
1612
1626
} catch ( err ) {
1613
1627
let be : B . Block = ( err as any ) . block ;
1614
1628
if ( be ) {
0 commit comments