Skip to content

Commit ff3d722

Browse files
committed
(feat) Add String Interpolation to AssemblyScript near/near-sdk-as#201
1 parent ed9b4cb commit ff3d722

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

src/ast.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ export abstract class Node {
376376
value: string,
377377
range: Range
378378
): StringLiteralExpression {
379-
var expr = new StringLiteralExpression();
380-
expr.range = range;
381-
expr.value = value;
382-
return expr;
379+
return new TemplateLiteralExpression(value, range);
383380
}
384381

385382
static createSuperExpression(
@@ -1443,12 +1440,16 @@ export class StringLiteralExpression extends LiteralExpression {
14431440
}
14441441
}
14451442

1446-
/** Represents a string template literal expression. */
1443+
/** Represents a string literal expression. */
14471444
export class TemplateLiteralExpression extends LiteralExpression {
1448-
literalKind = LiteralKind.TEMPLATE;
1449-
1450-
/** String value without quotes. */
1451-
value: string;
1445+
constructor(
1446+
/** String value without quotes. */
1447+
public expresssionParts: Expression[],
1448+
/** Source range. */
1449+
range: Range
1450+
) {
1451+
super(LiteralKind.TEMPLATE, range);
1452+
}
14521453
}
14531454

14541455
/** Represents a `super` expression. */

src/compiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8780,9 +8780,9 @@ export class Compiler extends DiagnosticEmitter {
87808780
return module.unreachable();
87818781
}
87828782

8783-
compileTemplateLiteral(arg0: TemplateLiteralExpression, constraints: Constraints): ExpressionRef {
8784-
const innerExpressions: ExpressionRef[] = [];
8785-
8783+
compileTemplateLiteral(expr: TemplateLiteralExpression, constraints: Constraints): ExpressionRef {
8784+
const innerExpressions: ExpressionRef[] = expr.expressionParts;
8785+
87868786
return 0;
87878787
}
87888788

src/tokenizer.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,8 @@ export class Tokenizer extends DiagnosticEmitter {
560560
return Token.STRINGLITERAL;
561561
}
562562
case CharCode.BACKTICK: { // TODO
563-
<<<<<<< HEAD
564-
return Token.TEMPLATELITERAL; // expects a call to readString
565-
=======
566563
this.pos = pos;
567564
return Token.STRINGLITERAL; // expects a call to readString
568-
>>>>>>> upstream/master
569565
}
570566
case CharCode.PERCENT: {
571567
++pos;
@@ -1086,11 +1082,6 @@ export class Tokenizer extends DiagnosticEmitter {
10861082

10871083
readString(quote: i32 = -1): string {
10881084
var text = this.source.text;
1089-
<<<<<<< HEAD
1090-
quote = quote == -1 ? text.charCodeAt(this.pos++) : quote;
1091-
var start = this.pos;
1092-
=======
1093-
>>>>>>> upstream/master
10941085
var end = this.end;
10951086
var pos = this.pos;
10961087
var quote = text.charCodeAt(pos++);
@@ -1105,15 +1096,7 @@ export class Tokenizer extends DiagnosticEmitter {
11051096
);
11061097
break;
11071098
}
1108-
<<<<<<< HEAD
1109-
let c = text.charCodeAt(this.pos);
1110-
if (quote == CharCode.BACKTICK && c == CharCode.DOLLAR) {
1111-
result += text.substring(start, this.pos);
1112-
break;
1113-
}
1114-
=======
11151099
let c = text.charCodeAt(pos);
1116-
>>>>>>> upstream/master
11171100
if (c == quote) {
11181101
result += text.substring(start, pos++);
11191102
break;

0 commit comments

Comments
 (0)