Files
rust_browser/tests/external/js262/fixtures/template-literal.js
Zachary D. Rowitsch 070391daaf Add JavaScript template literal support with string interpolation
Template literals (`hello ${name}`) are the last Tier 1 blocker before
shimming Test262's assert.js/sta.js harness files. The tokenizer eagerly
scans each template into a composite token (quasis + raw expression
strings + absolute byte offsets), and the parser re-tokenizes expressions
with span rebasing for correct source locations. Includes UTF-8-safe
quasi string building, nesting depth limits, and structural comment
skipping in nested expressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 14:27:53 -05:00

49 lines
967 B
JavaScript

// Simple (no interpolation)
console.log(`hello world`);
// Single variable interpolation
var name = "world";
console.log(`hello ${name}`);
// Multiple interpolations
var a = 2;
var b = 3;
console.log(`${a} + ${b} = ${a + b}`);
// Type coercion: numbers
console.log(`num: ${42}`);
// Type coercion: booleans
console.log(`bool: ${true}`);
// Type coercion: null
console.log(`val: ${null}`);
// Type coercion: undefined
console.log(`val: ${undefined}`);
// Multiline (real newlines)
console.log(`line1
line2`);
// Escape sequences
console.log(`backtick: \` dollar: \${ newline: \n`);
// Nested template
var x = "inner";
console.log(`outer ${`nested ${x}`} end`);
// Empty template
console.log(``);
// Function call in expression
function greet(n) { return "hi " + n; }
console.log(`${greet("Alice")}`);
// Object coercion
var obj = {};
console.log(`obj: ${obj}`);
// Expression with braces (object literal in expression)
console.log(`keys: ${typeof {}}`);