svelte2tsx 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +14 -7
  2. package/index.mjs +14 -7
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -3604,10 +3604,7 @@ class InlineComponent {
3604
3604
  // here, falling back to a any-typed component to ensure the user doesn't
3605
3605
  // get weird follup-errors all over the place. The diagnostic error
3606
3606
  // will be on the __sveltets_2_ensureComponent part, giving a more helpful message
3607
- this._name =
3608
- '$$_' +
3609
- (isSvelteComponentTag ? 'sveltecomponent' : this.node.name) +
3610
- this.computeDepth();
3607
+ this._name = '$$_' + sanitizePropName(this.node.name) + this.computeDepth();
3611
3608
  const constructorName = this._name + 'C';
3612
3609
  const nodeNameStart = isSvelteComponentTag
3613
3610
  ? this.node.expression.start
@@ -3885,12 +3882,22 @@ function handleAttribute(str, attr, parent, preserveCase, element) {
3885
3882
  parent.type === 'Element' &&
3886
3883
  numberOnlyAttributes.has(attr.name.toLowerCase()) &&
3887
3884
  !isNaN(attrVal.data);
3888
- const quote = ['"', "'"].includes(str.original[attrVal.start - 1])
3889
- ? str.original[attrVal.start - 1]
3890
- : '"';
3885
+ const includesTemplateLiteralQuote = attrVal.data.includes('`');
3886
+ const quote = !includesTemplateLiteralQuote
3887
+ ? '`'
3888
+ : ['"', "'"].includes(str.original[attrVal.start - 1])
3889
+ ? str.original[attrVal.start - 1]
3890
+ : '"';
3891
3891
  if (!needsNumberConversion) {
3892
3892
  attributeValue.push(quote);
3893
3893
  }
3894
+ if (includesTemplateLiteralQuote && attrVal.data.split('\n').length > 1) {
3895
+ // Multiline attribute value text which can't be wrapped in a template literal
3896
+ // -> ensure it's still a valid transformation by transforming the actual line break
3897
+ str.overwrite(attrVal.start, attrVal.end, attrVal.data.split('\n').join('\\n'), {
3898
+ contentOnly: true
3899
+ });
3900
+ }
3894
3901
  attributeValue.push([attrVal.start, attrVal.end]);
3895
3902
  if (!needsNumberConversion) {
3896
3903
  attributeValue.push(quote);
package/index.mjs CHANGED
@@ -3574,10 +3574,7 @@ class InlineComponent {
3574
3574
  // here, falling back to a any-typed component to ensure the user doesn't
3575
3575
  // get weird follup-errors all over the place. The diagnostic error
3576
3576
  // will be on the __sveltets_2_ensureComponent part, giving a more helpful message
3577
- this._name =
3578
- '$$_' +
3579
- (isSvelteComponentTag ? 'sveltecomponent' : this.node.name) +
3580
- this.computeDepth();
3577
+ this._name = '$$_' + sanitizePropName(this.node.name) + this.computeDepth();
3581
3578
  const constructorName = this._name + 'C';
3582
3579
  const nodeNameStart = isSvelteComponentTag
3583
3580
  ? this.node.expression.start
@@ -3855,12 +3852,22 @@ function handleAttribute(str, attr, parent, preserveCase, element) {
3855
3852
  parent.type === 'Element' &&
3856
3853
  numberOnlyAttributes.has(attr.name.toLowerCase()) &&
3857
3854
  !isNaN(attrVal.data);
3858
- const quote = ['"', "'"].includes(str.original[attrVal.start - 1])
3859
- ? str.original[attrVal.start - 1]
3860
- : '"';
3855
+ const includesTemplateLiteralQuote = attrVal.data.includes('`');
3856
+ const quote = !includesTemplateLiteralQuote
3857
+ ? '`'
3858
+ : ['"', "'"].includes(str.original[attrVal.start - 1])
3859
+ ? str.original[attrVal.start - 1]
3860
+ : '"';
3861
3861
  if (!needsNumberConversion) {
3862
3862
  attributeValue.push(quote);
3863
3863
  }
3864
+ if (includesTemplateLiteralQuote && attrVal.data.split('\n').length > 1) {
3865
+ // Multiline attribute value text which can't be wrapped in a template literal
3866
+ // -> ensure it's still a valid transformation by transforming the actual line break
3867
+ str.overwrite(attrVal.start, attrVal.end, attrVal.data.split('\n').join('\\n'), {
3868
+ contentOnly: true
3869
+ });
3870
+ }
3864
3871
  attributeValue.push([attrVal.start, attrVal.end]);
3865
3872
  if (!needsNumberConversion) {
3866
3873
  attributeValue.push(quote);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",