Skip to content

Commit ce8247d

Browse files
authored
Merge pull request #38 from Paneon/bugfix/props
Update typeScriptRegexProps
2 parents 0bce7ad + 6cff728 commit ce8247d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Compiler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ public function registerProperties(DOMElement $scriptElement)
278278
}
279279
}
280280

281-
$typeScriptRegexProps = '/\@Prop\(.*?default\s*\:\s*(?<defaultValue>\'(?:[^@](?!(?<![\\\\])\'))*.?\'|"(?:[^@](?!(?<![\\\\])"))*.?"|[^\s,]+).*?\)[^;]*?(?<propName>[a-zA-Z0-9_$]+)\!?\:[^;\@]*;/msx';
281+
$typeScriptRegexProps = '/\@Prop\(.*?default\s*\:\s*(?<defaultValue>\'(?:[^\n](?!(?<![\\\\])\'))*.?\'|"(?:[^\n](?!(?<![\\\\])"))*.?"|[a-zA-Z0-9_]+).*?\)[^;]*?(?<propName>[a-zA-Z0-9_$]+)\!?\:[^;\@]*;/msx';
282282

283283
if (preg_match_all($typeScriptRegexProps, $content, $typeScriptMatches, PREG_SET_ORDER )) {
284284
$this->properties = [];
285285
foreach ($typeScriptMatches as $typeScriptMatch) {
286-
$property = new Property($typeScriptMatch[2], '', true);
287-
$property->setDefault(trim($typeScriptMatch[1]));
288-
$this->properties[$typeScriptMatch[2]] = $property;
286+
$property = new Property($typeScriptMatch['propName'], '', true);
287+
$property->setDefault(trim($typeScriptMatch['defaultValue']));
288+
$this->properties[$typeScriptMatch['propName']] = $property;
289289
}
290290
}
291291
}

tests/fixtures/vue-props/binding-props-typescript-default.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
{% set propPresent = propPresent|default('') %}
33
{% set propWithTypeNumber = propWithTypeNumber|default(0) %}
44
{% set propPresentWithTypeAndDefault = propPresentWithTypeAndDefault|default('foo') %}
5+
{% set propPresentWithApostrophe = propPresentWithApostrophe|default('I\'m a text') %}
6+
{% set propPresentWithAt = propPresentWithAt|default('[email protected]') %}
57
<div class="{{class|default('')}}">
68
{{ test }}
79
</div>
8-

tests/fixtures/vue-props/binding-props-typescript-default.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import { Component, Prop, Vue } from 'vue-property-decorator';
99
1010
@Component
11-
export default class FromPrice extends Vue {
11+
export default class PropsExample extends Vue {
1212
@Prop({ type: Boolean, required: true }) ignored: boolean;
1313
@Prop({ default: false }) propBoolean: string;
1414
@Prop({ default: '' }) propPresent!: string;
1515
@Prop({ default: 0, type: Number }) propWithTypeNumber!: number;
1616
@Prop({ type: String, default: 'foo' }) readonly propPresentWithTypeAndDefault!: string;
17+
@Prop({ default: 'I\'m a text' }) readonly propPresentWithApostrophe!: string;
18+
@Prop({ default: '[email protected]' }) readonly propPresentWithAt!: string;
1719
}
1820
</script>

0 commit comments

Comments
 (0)