Skip to content

Commit bd0bf20

Browse files
committed
Add data handling for typescript
1 parent cd2f83e commit bd0bf20

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Compiler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ public function registerData(DOMElement $scriptElement): void
498498
$content = $this->innerHtmlOfNode($scriptElement);
499499
if ($scriptElement->hasAttribute('lang') && $scriptElement->getAttribute('lang') === 'ts') {
500500
// TypeScript
501+
preg_match_all('/private\s+(\S+)\s*=\s*(.+?);\n/msi', $content, $matches, PREG_SET_ORDER);
502+
foreach ($matches as $match) {
503+
$this->data[] = new Data(
504+
trim($match[1]),
505+
trim($this->builder->refactorCondition(str_replace('this.', '', $match[2])))
506+
);
507+
}
501508
} else {
502509
// JavaScript
503510
if (preg_match('/data\(\)\s*{\s*return\s*{(.+)\s*}\s*;\s*}\s*,/msi', $content, $match)) {
@@ -534,7 +541,7 @@ public function registerData(DOMElement $scriptElement): void
534541
if (substr_count($data, ':')) {
535542
[$name, $value] = explode(':', $data, 2);
536543
$this->data[] = new Data(
537-
trim($name, "\ \t\n\r\0\x0B\"'"),
544+
trim($name),
538545
trim($this->builder->refactorCondition(str_replace('this.', '', $value)))
539546
);
540547
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
{% set bar = bar|default('baz') %}
2+
{% set myNumber = 1 %}
3+
{% set myString = 'foo' %}
4+
{% set myArray = ['a', 'b', 'c'] %}
5+
{% set myObject = { a: 'x', b: 'y', c: 'z' } %}
26
<div class="{{ class|default('') }}" style="{{ style|default('') }}"> Hello World! </div>

0 commit comments

Comments
 (0)