svelte2tsx 0.6.10 → 0.6.12
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.
- package/index.js +81 -45
- package/index.mjs +167 -131
- package/package.json +3 -3
- package/svelte-shims.d.ts +4 -4
package/index.js
CHANGED
|
@@ -23,7 +23,6 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts);
|
|
27
26
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
28
27
|
|
|
29
28
|
const comma = ','.charCodeAt(0);
|
|
@@ -2341,7 +2340,10 @@ const oneWayBindingAttributes = new Set([
|
|
|
2341
2340
|
'seekable',
|
|
2342
2341
|
'seeking',
|
|
2343
2342
|
'played',
|
|
2344
|
-
'ended'
|
|
2343
|
+
'ended',
|
|
2344
|
+
'readyState',
|
|
2345
|
+
'naturalWidth',
|
|
2346
|
+
'naturalHeight'
|
|
2345
2347
|
]);
|
|
2346
2348
|
/**
|
|
2347
2349
|
* List of all binding names that are transformed to sth like `binding = variable`.
|
|
@@ -2827,6 +2829,7 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
|
|
|
2827
2829
|
case 'Window':
|
|
2828
2830
|
case 'Head':
|
|
2829
2831
|
case 'Title':
|
|
2832
|
+
case 'Document':
|
|
2830
2833
|
case 'Body':
|
|
2831
2834
|
case 'Slot':
|
|
2832
2835
|
case 'SlotTemplate':
|
|
@@ -2903,6 +2906,7 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
|
|
|
2903
2906
|
case 'Head':
|
|
2904
2907
|
case 'Title':
|
|
2905
2908
|
case 'Body':
|
|
2909
|
+
case 'Document':
|
|
2906
2910
|
case 'Slot':
|
|
2907
2911
|
case 'SlotTemplate':
|
|
2908
2912
|
if (node.name !== '!DOCTYPE') {
|
|
@@ -3690,14 +3694,28 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3690
3694
|
const load = exports.get('load');
|
|
3691
3695
|
if ((load === null || load === void 0 ? void 0 : load.type) === 'function' && load.node.parameters.length === 1 && !load.hasTypeDefinition) {
|
|
3692
3696
|
const pos = load.node.parameters[0].getEnd();
|
|
3693
|
-
const inserted = surround(`: import('./$types').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`);
|
|
3697
|
+
const inserted = surround(`: import('./$types.js').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`);
|
|
3694
3698
|
insert(pos, inserted);
|
|
3695
3699
|
}
|
|
3700
|
+
// add type to entries function if not explicitly typed
|
|
3701
|
+
const entries = exports.get('entries');
|
|
3702
|
+
if ((entries === null || entries === void 0 ? void 0 : entries.type) === 'function' &&
|
|
3703
|
+
entries.node.parameters.length === 0 &&
|
|
3704
|
+
!entries.hasTypeDefinition &&
|
|
3705
|
+
!basename.includes('layout')) {
|
|
3706
|
+
if (!entries.node.type && entries.node.body) {
|
|
3707
|
+
const returnPos = ts.isArrowFunction(entries.node)
|
|
3708
|
+
? entries.node.equalsGreaterThanToken.getStart()
|
|
3709
|
+
: entries.node.body.getStart();
|
|
3710
|
+
const returnInsertion = surround(`: ReturnType<import('./$types.js').EntryGenerator> `);
|
|
3711
|
+
insert(returnPos, returnInsertion);
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3696
3714
|
// add type to actions variable if not explicitly typed
|
|
3697
3715
|
const actions = exports.get('actions');
|
|
3698
3716
|
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
3699
3717
|
const pos = actions.node.initializer.getEnd();
|
|
3700
|
-
const inserted = surround(` satisfies import('./$types').Actions`);
|
|
3718
|
+
const inserted = surround(` satisfies import('./$types.js').Actions`);
|
|
3701
3719
|
insert(pos, inserted);
|
|
3702
3720
|
}
|
|
3703
3721
|
addTypeToVariable(exports, surround, insert, 'prerender', `boolean | 'auto'`);
|
|
@@ -3706,7 +3724,7 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3706
3724
|
addTypeToVariable(exports, surround, insert, 'csr', `boolean`);
|
|
3707
3725
|
// add types to GET/PUT/POST/PATCH/DELETE/OPTIONS if not explicitly typed
|
|
3708
3726
|
const insertApiMethod = (name) => {
|
|
3709
|
-
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types').RequestEvent`, `Response | Promise<Response>`);
|
|
3727
|
+
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types.js').RequestEvent`, `Response | Promise<Response>`);
|
|
3710
3728
|
};
|
|
3711
3729
|
insertApiMethod('GET');
|
|
3712
3730
|
insertApiMethod('PUT');
|
|
@@ -3893,6 +3911,13 @@ function updatePrepends(str, index, toAppend, removeExisting) {
|
|
|
3893
3911
|
str.__prepends__.set(index, prepends);
|
|
3894
3912
|
return prepends;
|
|
3895
3913
|
}
|
|
3914
|
+
/**
|
|
3915
|
+
* Returns the prepends that were added at the given index (if any).
|
|
3916
|
+
*/
|
|
3917
|
+
function getCurrentPrepends(str, index) {
|
|
3918
|
+
var _a;
|
|
3919
|
+
return ((_a = str.__prepends__) === null || _a === void 0 ? void 0 : _a.get(index)) || [];
|
|
3920
|
+
}
|
|
3896
3921
|
|
|
3897
3922
|
function is$$PropsDeclaration(node) {
|
|
3898
3923
|
return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
|
|
@@ -3928,7 +3953,7 @@ class ExportedNames {
|
|
|
3928
3953
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3929
3954
|
n.name.getText() === 'snapshot';
|
|
3930
3955
|
// TS types are not allowed in JS files, but TS will still pick it up and the ignore comment will filter out the error
|
|
3931
|
-
const kitType = isKitExport && !type ? `: import('./$types').Snapshot` : '';
|
|
3956
|
+
const kitType = isKitExport && !type ? `: import('./$types.js').Snapshot` : '';
|
|
3932
3957
|
const nameEnd = n.name.end + this.astOffset;
|
|
3933
3958
|
if (kitType) {
|
|
3934
3959
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
@@ -3993,7 +4018,7 @@ class ExportedNames {
|
|
|
3993
4018
|
(name === 'data' || name === 'form' || name === 'snapshot');
|
|
3994
4019
|
// TS types are not allowed in JS files, but TS will still pick it up and the ignore comment will filter out the error
|
|
3995
4020
|
const kitType = isKitExport && !type
|
|
3996
|
-
? `: import('./$types').${name === 'data'
|
|
4021
|
+
? `: import('./$types.js').${name === 'data'
|
|
3997
4022
|
? this.basename.includes('layout')
|
|
3998
4023
|
? 'LayoutData'
|
|
3999
4024
|
: 'PageData'
|
|
@@ -4608,7 +4633,16 @@ class ImplicitStoreValues {
|
|
|
4608
4633
|
const nodeEnd = ts.isVariableDeclarationList(node.parent) && node.parent.declarations.length > 1
|
|
4609
4634
|
? node.parent.declarations[node.parent.declarations.length - 1].getEnd()
|
|
4610
4635
|
: node.getEnd();
|
|
4611
|
-
|
|
4636
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1950
|
|
4637
|
+
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4638
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4639
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4640
|
+
if (getCurrentPrepends(str, nodeEnd + astOffset).length) {
|
|
4641
|
+
preprendStr(str, nodeEnd + astOffset, storeDeclarations);
|
|
4642
|
+
}
|
|
4643
|
+
else {
|
|
4644
|
+
str.appendRight(nodeEnd + astOffset, storeDeclarations);
|
|
4645
|
+
}
|
|
4612
4646
|
}
|
|
4613
4647
|
attachStoreValueDeclarationToReactiveAssignment(node, astOffset, str) {
|
|
4614
4648
|
const storeNames = getNamesFromLabeledStatement(node).filter((name) => this.accessedStores.has(name));
|
|
@@ -4617,9 +4651,10 @@ class ImplicitStoreValues {
|
|
|
4617
4651
|
}
|
|
4618
4652
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4619
4653
|
const endPos = node.getEnd() + astOffset;
|
|
4620
|
-
//
|
|
4654
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1097
|
|
4621
4655
|
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4622
|
-
// or investigate altering the inner workings of SourceMap
|
|
4656
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4657
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4623
4658
|
if (str.original.charAt(endPos - 1) !== ';') {
|
|
4624
4659
|
preprendStr(str, endPos, storeDeclarations);
|
|
4625
4660
|
}
|
|
@@ -5346,7 +5381,7 @@ class InterfacesAndTypes {
|
|
|
5346
5381
|
function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, basename) {
|
|
5347
5382
|
const htmlx = str.original;
|
|
5348
5383
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
5349
|
-
const tsAst =
|
|
5384
|
+
const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
5350
5385
|
const astOffset = script.content.start;
|
|
5351
5386
|
const exportedNames = new ExportedNames(str, astOffset, basename);
|
|
5352
5387
|
const generics = new Generics(str, astOffset);
|
|
@@ -5391,12 +5426,12 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5391
5426
|
uses$$slots = true;
|
|
5392
5427
|
return;
|
|
5393
5428
|
}
|
|
5394
|
-
if (
|
|
5429
|
+
if (ts.isLabeledStatement(parent) && parent.label == ident) {
|
|
5395
5430
|
return;
|
|
5396
5431
|
}
|
|
5397
|
-
if (isDeclaration ||
|
|
5432
|
+
if (isDeclaration || ts.isParameter(parent)) {
|
|
5398
5433
|
if (isNotPropertyNameOfImport(ident) &&
|
|
5399
|
-
(!
|
|
5434
|
+
(!ts.isBindingElement(ident.parent) || ident.parent.name == ident)) {
|
|
5400
5435
|
// we are a key, not a name, so don't care
|
|
5401
5436
|
if (ident.text.startsWith('$') || scope == rootScope) {
|
|
5402
5437
|
// track all top level declared identifiers and all $ prefixed identifiers
|
|
@@ -5407,13 +5442,13 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5407
5442
|
else {
|
|
5408
5443
|
//track potential store usage to be resolved
|
|
5409
5444
|
if (ident.text.startsWith('$')) {
|
|
5410
|
-
if ((!
|
|
5411
|
-
(!
|
|
5412
|
-
!
|
|
5413
|
-
!
|
|
5414
|
-
!
|
|
5415
|
-
!
|
|
5416
|
-
!
|
|
5445
|
+
if ((!ts.isPropertyAccessExpression(parent) || parent.expression == ident) &&
|
|
5446
|
+
(!ts.isPropertyAssignment(parent) || parent.initializer == ident) &&
|
|
5447
|
+
!ts.isPropertySignature(parent) &&
|
|
5448
|
+
!ts.isPropertyDeclaration(parent) &&
|
|
5449
|
+
!ts.isTypeReferenceNode(parent) &&
|
|
5450
|
+
!ts.isTypeAliasDeclaration(parent) &&
|
|
5451
|
+
!ts.isInterfaceDeclaration(parent)) {
|
|
5417
5452
|
pendingStoreResolutions.push({ node: ident, parent, scope });
|
|
5418
5453
|
}
|
|
5419
5454
|
}
|
|
@@ -5432,71 +5467,69 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5432
5467
|
if (is$$PropsDeclaration(node)) {
|
|
5433
5468
|
exportedNames.uses$$Props = true;
|
|
5434
5469
|
}
|
|
5435
|
-
if (
|
|
5470
|
+
if (ts.isVariableStatement(node)) {
|
|
5436
5471
|
exportedNames.handleVariableStatement(node, parent);
|
|
5437
5472
|
}
|
|
5438
|
-
if (
|
|
5473
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
5439
5474
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5440
|
-
pushScope();
|
|
5441
|
-
onLeaveCallbacks.push(() => popScope());
|
|
5442
5475
|
}
|
|
5443
|
-
if (
|
|
5476
|
+
if (ts.isClassDeclaration(node)) {
|
|
5444
5477
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5445
5478
|
}
|
|
5446
|
-
if (
|
|
5479
|
+
if (ts.isBlock(node) || ts.isFunctionLike(node)) {
|
|
5447
5480
|
pushScope();
|
|
5448
5481
|
onLeaveCallbacks.push(() => popScope());
|
|
5449
5482
|
}
|
|
5450
|
-
if (
|
|
5483
|
+
if (ts.isExportDeclaration(node)) {
|
|
5451
5484
|
exportedNames.handleExportDeclaration(node);
|
|
5452
5485
|
}
|
|
5453
|
-
if (
|
|
5486
|
+
if (ts.isImportDeclaration(node)) {
|
|
5454
5487
|
handleImportDeclaration(node, str, astOffset, script.start, tsAst);
|
|
5455
5488
|
// Check if import is the event dispatcher
|
|
5456
5489
|
events.checkIfImportIsEventDispatcher(node);
|
|
5457
5490
|
}
|
|
5458
5491
|
// workaround for import statement completion
|
|
5459
|
-
if (
|
|
5492
|
+
if (ts.isImportEqualsDeclaration(node)) {
|
|
5460
5493
|
const end = node.getEnd() + astOffset;
|
|
5461
5494
|
if (str.original[end - 1] !== ';') {
|
|
5462
5495
|
preprendStr(str, end, ';');
|
|
5463
5496
|
}
|
|
5464
5497
|
}
|
|
5465
|
-
if (
|
|
5498
|
+
if (ts.isVariableDeclaration(node)) {
|
|
5466
5499
|
events.checkIfIsStringLiteralDeclaration(node);
|
|
5467
5500
|
events.checkIfDeclarationInstantiatedEventDispatcher(node);
|
|
5468
5501
|
implicitStoreValues.addVariableDeclaration(node);
|
|
5469
5502
|
}
|
|
5470
|
-
if (
|
|
5503
|
+
if (ts.isCallExpression(node)) {
|
|
5471
5504
|
events.checkIfCallExpressionIsDispatch(node);
|
|
5472
5505
|
}
|
|
5473
|
-
if (
|
|
5506
|
+
if (ts.isVariableDeclaration(parent) && parent.name == node) {
|
|
5474
5507
|
isDeclaration = true;
|
|
5475
5508
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5476
5509
|
}
|
|
5477
|
-
if (
|
|
5510
|
+
if (ts.isBindingElement(parent) && parent.name == node) {
|
|
5478
5511
|
isDeclaration = true;
|
|
5479
5512
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5480
5513
|
}
|
|
5481
|
-
if (
|
|
5514
|
+
if (ts.isImportClause(node)) {
|
|
5482
5515
|
isDeclaration = true;
|
|
5483
5516
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5484
5517
|
implicitStoreValues.addImportStatement(node);
|
|
5485
5518
|
}
|
|
5486
|
-
if (
|
|
5519
|
+
if (ts.isImportSpecifier(node)) {
|
|
5487
5520
|
implicitStoreValues.addImportStatement(node);
|
|
5488
5521
|
}
|
|
5489
|
-
if (
|
|
5522
|
+
if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) {
|
|
5490
5523
|
interfacesAndTypes.node = node;
|
|
5491
5524
|
interfacesAndTypes.add(node);
|
|
5492
5525
|
onLeaveCallbacks.push(() => (interfacesAndTypes.node = null));
|
|
5493
5526
|
}
|
|
5494
5527
|
//handle stores etc
|
|
5495
|
-
if (
|
|
5528
|
+
if (ts.isIdentifier(node)) {
|
|
5496
5529
|
handleIdentifier(node, parent);
|
|
5497
5530
|
}
|
|
5498
5531
|
//track implicit declarations in reactive blocks at the top level
|
|
5499
|
-
if (
|
|
5532
|
+
if (ts.isLabeledStatement(node) &&
|
|
5500
5533
|
parent == tsAst && //top level
|
|
5501
5534
|
node.label.text == '$' &&
|
|
5502
5535
|
node.statement) {
|
|
@@ -5510,11 +5543,11 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5510
5543
|
// Defensively call function (checking for undefined) because it got added only recently (TS 4.0)
|
|
5511
5544
|
// and therefore might break people using older TS versions
|
|
5512
5545
|
// Don't transform in ts mode because <type>value type assertions are valid in this case
|
|
5513
|
-
if (mode !== 'ts' && ((_a =
|
|
5546
|
+
if (mode !== 'ts' && ((_a = ts.isTypeAssertionExpression) === null || _a === void 0 ? void 0 : _a.call(ts, node))) {
|
|
5514
5547
|
handleTypeAssertion(str, node, astOffset);
|
|
5515
5548
|
}
|
|
5516
5549
|
//to save a bunch of condition checks on each node, we recurse into processChild which skips all the checks for top level items
|
|
5517
|
-
|
|
5550
|
+
ts.forEachChild(node, (n) => walk(n, node));
|
|
5518
5551
|
//fire off the on leave callbacks
|
|
5519
5552
|
onLeaveCallbacks.map((c) => c());
|
|
5520
5553
|
};
|
|
@@ -5551,7 +5584,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5551
5584
|
}
|
|
5552
5585
|
function transformInterfacesToTypes(tsAst, str, astOffset, movedNodes) {
|
|
5553
5586
|
tsAst.statements
|
|
5554
|
-
.filter(
|
|
5587
|
+
.filter(ts.isInterfaceDeclaration)
|
|
5555
5588
|
.filter((i) => !movedNodes.includes(i))
|
|
5556
5589
|
.forEach((node) => {
|
|
5557
5590
|
var _a;
|
|
@@ -5680,7 +5713,8 @@ class __sveltets_Render${genericsDef} {
|
|
|
5680
5713
|
}
|
|
5681
5714
|
else {
|
|
5682
5715
|
statement +=
|
|
5683
|
-
|
|
5716
|
+
'\n\nimport { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" \n' +
|
|
5717
|
+
`${doc}export default class${className ? ` ${className}` : ''}${genericsDef} extends __SvelteComponentTyped__<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> {` +
|
|
5684
5718
|
exportedNames.createClassGetters() +
|
|
5685
5719
|
(usesAccessors ? exportedNames.createClassAccessors() : '') +
|
|
5686
5720
|
'\n}';
|
|
@@ -6153,6 +6187,7 @@ async function emitDts(config) {
|
|
|
6153
6187
|
program.emit();
|
|
6154
6188
|
}
|
|
6155
6189
|
function loadTsconfig(config, svelteMap) {
|
|
6190
|
+
var _a;
|
|
6156
6191
|
const libRoot = config.libRoot || process.cwd();
|
|
6157
6192
|
const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
|
|
6158
6193
|
let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
|
|
@@ -6195,7 +6230,9 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6195
6230
|
options: {
|
|
6196
6231
|
...options,
|
|
6197
6232
|
noEmit: false,
|
|
6198
|
-
moduleResolution:
|
|
6233
|
+
moduleResolution:
|
|
6234
|
+
// NodeJS: up to 4.9, Node10: since 5.0
|
|
6235
|
+
(_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10,
|
|
6199
6236
|
declaration: true,
|
|
6200
6237
|
emitDeclarationOnly: true,
|
|
6201
6238
|
declarationDir: config.declarationDir,
|
|
@@ -6280,7 +6317,6 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6280
6317
|
return resolveModuleName(moduleName, containingFile, compilerOptions);
|
|
6281
6318
|
});
|
|
6282
6319
|
};
|
|
6283
|
-
// @ts-expect-error remove once we bump dev dep to TS 5
|
|
6284
6320
|
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, _redirectedReference, compilerOptions) => {
|
|
6285
6321
|
return moduleLiterals.map((moduleLiteral) => {
|
|
6286
6322
|
return {
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parse, walk as walk$1 } from 'svelte/compiler';
|
|
2
2
|
import dedent from 'dedent-js';
|
|
3
|
-
import
|
|
4
|
-
import ts__default from 'typescript';
|
|
3
|
+
import ts from 'typescript';
|
|
5
4
|
import * as path from 'path';
|
|
6
5
|
import path__default from 'path';
|
|
7
6
|
import { pascalCase } from 'pascal-case';
|
|
@@ -2321,7 +2320,10 @@ const oneWayBindingAttributes = new Set([
|
|
|
2321
2320
|
'seekable',
|
|
2322
2321
|
'seeking',
|
|
2323
2322
|
'played',
|
|
2324
|
-
'ended'
|
|
2323
|
+
'ended',
|
|
2324
|
+
'readyState',
|
|
2325
|
+
'naturalWidth',
|
|
2326
|
+
'naturalHeight'
|
|
2325
2327
|
]);
|
|
2326
2328
|
/**
|
|
2327
2329
|
* List of all binding names that are transformed to sth like `binding = variable`.
|
|
@@ -2807,6 +2809,7 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
|
|
|
2807
2809
|
case 'Window':
|
|
2808
2810
|
case 'Head':
|
|
2809
2811
|
case 'Title':
|
|
2812
|
+
case 'Document':
|
|
2810
2813
|
case 'Body':
|
|
2811
2814
|
case 'Slot':
|
|
2812
2815
|
case 'SlotTemplate':
|
|
@@ -2883,6 +2886,7 @@ function convertHtmlxToJsx(str, ast, onWalk = null, onLeave = null, options = {}
|
|
|
2883
2886
|
case 'Head':
|
|
2884
2887
|
case 'Title':
|
|
2885
2888
|
case 'Body':
|
|
2889
|
+
case 'Document':
|
|
2886
2890
|
case 'Slot':
|
|
2887
2891
|
case 'SlotTemplate':
|
|
2888
2892
|
if (node.name !== '!DOCTYPE') {
|
|
@@ -2937,33 +2941,33 @@ class ComponentDocumentation {
|
|
|
2937
2941
|
}
|
|
2938
2942
|
|
|
2939
2943
|
function isInterfaceOrTypeDeclaration(node) {
|
|
2940
|
-
return
|
|
2944
|
+
return ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node);
|
|
2941
2945
|
}
|
|
2942
2946
|
function findExportKeyword(node) {
|
|
2943
2947
|
var _a;
|
|
2944
|
-
return
|
|
2945
|
-
? (_a =
|
|
2948
|
+
return ts.canHaveModifiers(node)
|
|
2949
|
+
? (_a = ts.getModifiers(node)) === null || _a === void 0 ? void 0 : _a.find((x) => x.kind == ts.SyntaxKind.ExportKeyword)
|
|
2946
2950
|
: undefined;
|
|
2947
2951
|
}
|
|
2948
2952
|
/**
|
|
2949
2953
|
* Node is like `bla = ...` or `{bla} = ...` or `[bla] = ...`
|
|
2950
2954
|
*/
|
|
2951
2955
|
function isAssignmentBinaryExpr(node) {
|
|
2952
|
-
return (
|
|
2953
|
-
node.operatorToken.kind ==
|
|
2954
|
-
(
|
|
2955
|
-
|
|
2956
|
-
|
|
2956
|
+
return (ts.isBinaryExpression(node) &&
|
|
2957
|
+
node.operatorToken.kind == ts.SyntaxKind.EqualsToken &&
|
|
2958
|
+
(ts.isIdentifier(node.left) ||
|
|
2959
|
+
ts.isObjectLiteralExpression(node.left) ||
|
|
2960
|
+
ts.isArrayLiteralExpression(node.left)));
|
|
2957
2961
|
}
|
|
2958
2962
|
/**
|
|
2959
2963
|
* Returns if node is like `$: bla = ...` or `$: ({bla} = ...)` or `$: [bla] = ...=`
|
|
2960
2964
|
*/
|
|
2961
2965
|
function getBinaryAssignmentExpr(node) {
|
|
2962
|
-
if (
|
|
2966
|
+
if (ts.isExpressionStatement(node.statement)) {
|
|
2963
2967
|
if (isAssignmentBinaryExpr(node.statement.expression)) {
|
|
2964
2968
|
return node.statement.expression;
|
|
2965
2969
|
}
|
|
2966
|
-
if (
|
|
2970
|
+
if (ts.isParenthesizedExpression(node.statement.expression) &&
|
|
2967
2971
|
isAssignmentBinaryExpr(node.statement.expression.expression)) {
|
|
2968
2972
|
return node.statement.expression.expression;
|
|
2969
2973
|
}
|
|
@@ -2973,20 +2977,20 @@ function getBinaryAssignmentExpr(node) {
|
|
|
2973
2977
|
* Returns true if node is like `({bla} ..)` or `([bla] ...)`
|
|
2974
2978
|
*/
|
|
2975
2979
|
function isParenthesizedObjectOrArrayLiteralExpression(node) {
|
|
2976
|
-
return (
|
|
2977
|
-
|
|
2978
|
-
(
|
|
2979
|
-
|
|
2980
|
+
return (ts.isParenthesizedExpression(node) &&
|
|
2981
|
+
ts.isBinaryExpression(node.expression) &&
|
|
2982
|
+
(ts.isObjectLiteralExpression(node.expression.left) ||
|
|
2983
|
+
ts.isArrayLiteralExpression(node.expression.left)));
|
|
2980
2984
|
}
|
|
2981
2985
|
/**
|
|
2982
2986
|
*
|
|
2983
2987
|
* Adapted from https://github.com/Rich-Harris/periscopic/blob/d7a820b04e1f88b452313ab3e54771b352f0defb/src/index.ts#L150
|
|
2984
2988
|
*/
|
|
2985
2989
|
function extractIdentifiers(node, identifiers = []) {
|
|
2986
|
-
if (
|
|
2990
|
+
if (ts.isIdentifier(node)) {
|
|
2987
2991
|
identifiers.push(node);
|
|
2988
2992
|
}
|
|
2989
|
-
else if (
|
|
2993
|
+
else if (ts.isBindingElement(node)) {
|
|
2990
2994
|
extractIdentifiers(node.name, identifiers);
|
|
2991
2995
|
}
|
|
2992
2996
|
else if (isMember$1(node)) {
|
|
@@ -2994,33 +2998,33 @@ function extractIdentifiers(node, identifiers = []) {
|
|
|
2994
2998
|
while (isMember$1(object)) {
|
|
2995
2999
|
object = object.expression;
|
|
2996
3000
|
}
|
|
2997
|
-
if (
|
|
3001
|
+
if (ts.isIdentifier(object)) {
|
|
2998
3002
|
identifiers.push(object);
|
|
2999
3003
|
}
|
|
3000
3004
|
}
|
|
3001
|
-
else if (
|
|
3005
|
+
else if (ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node)) {
|
|
3002
3006
|
node.elements.forEach((element) => {
|
|
3003
3007
|
extractIdentifiers(element, identifiers);
|
|
3004
3008
|
});
|
|
3005
3009
|
}
|
|
3006
|
-
else if (
|
|
3010
|
+
else if (ts.isObjectLiteralExpression(node)) {
|
|
3007
3011
|
node.properties.forEach((child) => {
|
|
3008
|
-
if (
|
|
3012
|
+
if (ts.isSpreadAssignment(child)) {
|
|
3009
3013
|
extractIdentifiers(child.expression, identifiers);
|
|
3010
3014
|
}
|
|
3011
|
-
else if (
|
|
3015
|
+
else if (ts.isShorthandPropertyAssignment(child)) {
|
|
3012
3016
|
// in ts Ast { a = 1 } and { a } are both ShorthandPropertyAssignment
|
|
3013
3017
|
extractIdentifiers(child.name, identifiers);
|
|
3014
3018
|
}
|
|
3015
|
-
else if (
|
|
3019
|
+
else if (ts.isPropertyAssignment(child)) {
|
|
3016
3020
|
// { a: b }
|
|
3017
3021
|
extractIdentifiers(child.initializer, identifiers);
|
|
3018
3022
|
}
|
|
3019
3023
|
});
|
|
3020
3024
|
}
|
|
3021
|
-
else if (
|
|
3025
|
+
else if (ts.isArrayLiteralExpression(node)) {
|
|
3022
3026
|
node.elements.forEach((element) => {
|
|
3023
|
-
if (
|
|
3027
|
+
if (ts.isSpreadElement(element)) {
|
|
3024
3028
|
extractIdentifiers(element, identifiers);
|
|
3025
3029
|
}
|
|
3026
3030
|
else {
|
|
@@ -3028,13 +3032,13 @@ function extractIdentifiers(node, identifiers = []) {
|
|
|
3028
3032
|
}
|
|
3029
3033
|
});
|
|
3030
3034
|
}
|
|
3031
|
-
else if (
|
|
3035
|
+
else if (ts.isBinaryExpression(node)) {
|
|
3032
3036
|
extractIdentifiers(node.left, identifiers);
|
|
3033
3037
|
}
|
|
3034
3038
|
return identifiers;
|
|
3035
3039
|
}
|
|
3036
3040
|
function isMember$1(node) {
|
|
3037
|
-
return
|
|
3041
|
+
return ts.isElementAccessExpression(node) || ts.isPropertyAccessExpression(node);
|
|
3038
3042
|
}
|
|
3039
3043
|
/**
|
|
3040
3044
|
* Returns variable at given level with given name,
|
|
@@ -3042,8 +3046,8 @@ function isMember$1(node) {
|
|
|
3042
3046
|
*/
|
|
3043
3047
|
function getVariableAtTopLevel(node, identifierName) {
|
|
3044
3048
|
for (const child of node.statements) {
|
|
3045
|
-
if (
|
|
3046
|
-
const variable = child.declarationList.declarations.find((declaration) =>
|
|
3049
|
+
if (ts.isVariableStatement(child)) {
|
|
3050
|
+
const variable = child.declarationList.declarations.find((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === identifierName);
|
|
3047
3051
|
if (variable) {
|
|
3048
3052
|
return variable;
|
|
3049
3053
|
}
|
|
@@ -3056,12 +3060,12 @@ function getVariableAtTopLevel(node, identifierName) {
|
|
|
3056
3060
|
function getLastLeadingDoc(node) {
|
|
3057
3061
|
var _a;
|
|
3058
3062
|
const nodeText = node.getFullText();
|
|
3059
|
-
const comments = (_a =
|
|
3060
|
-
.getLeadingCommentRanges(nodeText, 0)) === null || _a === void 0 ? void 0 : _a.filter((c) => c.kind ===
|
|
3063
|
+
const comments = (_a = ts
|
|
3064
|
+
.getLeadingCommentRanges(nodeText, 0)) === null || _a === void 0 ? void 0 : _a.filter((c) => c.kind === ts.SyntaxKind.MultiLineCommentTrivia);
|
|
3061
3065
|
const comment = comments === null || comments === void 0 ? void 0 : comments[(comments === null || comments === void 0 ? void 0 : comments.length) - 1];
|
|
3062
3066
|
if (comment) {
|
|
3063
3067
|
let commentText = nodeText.substring(comment.pos, comment.end);
|
|
3064
|
-
const typedefTags =
|
|
3068
|
+
const typedefTags = ts.getAllJSDocTagsOfKind(node, ts.SyntaxKind.JSDocTypedefTag);
|
|
3065
3069
|
typedefTags
|
|
3066
3070
|
.filter((tag) => tag.pos >= comment.pos)
|
|
3067
3071
|
.map((tag) => nodeText.substring(tag.pos, tag.end))
|
|
@@ -3076,7 +3080,7 @@ function getLastLeadingDoc(node) {
|
|
|
3076
3080
|
* In other words: It is not `a` in `import {a as b} from ..`
|
|
3077
3081
|
*/
|
|
3078
3082
|
function isNotPropertyNameOfImport(identifier) {
|
|
3079
|
-
return (!
|
|
3083
|
+
return (!ts.isImportSpecifier(identifier.parent) || identifier.parent.propertyName !== identifier);
|
|
3080
3084
|
}
|
|
3081
3085
|
/**
|
|
3082
3086
|
* Extract the variable names that are assigned to out of a labeled statement.
|
|
@@ -3097,9 +3101,9 @@ function getNamesFromLabeledStatement(node) {
|
|
|
3097
3101
|
*/
|
|
3098
3102
|
function moveNode(node, str, astOffset, scriptStart, sourceFile) {
|
|
3099
3103
|
var _a;
|
|
3100
|
-
const scanner =
|
|
3104
|
+
const scanner = ts.createScanner(sourceFile.languageVersion,
|
|
3101
3105
|
/*skipTrivia*/ false, sourceFile.languageVariant);
|
|
3102
|
-
const comments = (_a =
|
|
3106
|
+
const comments = (_a = ts.getLeadingCommentRanges(node.getFullText(), 0)) !== null && _a !== void 0 ? _a : [];
|
|
3103
3107
|
if (!comments.some((comment) => comment.hasTrailingNewLine) &&
|
|
3104
3108
|
isNewGroup(sourceFile, node, scanner)) {
|
|
3105
3109
|
str.appendRight(node.getStart() + astOffset, '\n');
|
|
@@ -3126,7 +3130,7 @@ function isNewGroup(sourceFile, topLevelImportDecl, scanner) {
|
|
|
3126
3130
|
let numberOfNewLines = 0;
|
|
3127
3131
|
while (scanner.getTokenPos() < endPos) {
|
|
3128
3132
|
const tokenKind = scanner.scan();
|
|
3129
|
-
if (tokenKind ===
|
|
3133
|
+
if (tokenKind === ts.SyntaxKind.NewLineTrivia) {
|
|
3130
3134
|
numberOfNewLines++;
|
|
3131
3135
|
if (numberOfNewLines >= 2) {
|
|
3132
3136
|
return true;
|
|
@@ -3244,16 +3248,16 @@ class ComponentEventsFromInterface {
|
|
|
3244
3248
|
}
|
|
3245
3249
|
extractEvents(node) {
|
|
3246
3250
|
const map = new Map();
|
|
3247
|
-
if (
|
|
3251
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
3248
3252
|
this.extractProperties(node.members, map);
|
|
3249
3253
|
}
|
|
3250
3254
|
else {
|
|
3251
|
-
if (
|
|
3255
|
+
if (ts.isTypeLiteralNode(node.type)) {
|
|
3252
3256
|
this.extractProperties(node.type.members, map);
|
|
3253
3257
|
}
|
|
3254
|
-
else if (
|
|
3258
|
+
else if (ts.isIntersectionTypeNode(node.type)) {
|
|
3255
3259
|
node.type.types.forEach((type) => {
|
|
3256
|
-
if (
|
|
3260
|
+
if (ts.isTypeLiteralNode(type)) {
|
|
3257
3261
|
this.extractProperties(type.members, map);
|
|
3258
3262
|
}
|
|
3259
3263
|
});
|
|
@@ -3262,7 +3266,7 @@ class ComponentEventsFromInterface {
|
|
|
3262
3266
|
return map;
|
|
3263
3267
|
}
|
|
3264
3268
|
extractProperties(members, map) {
|
|
3265
|
-
members.filter(
|
|
3269
|
+
members.filter(ts.isPropertySignature).forEach((member) => {
|
|
3266
3270
|
var _a;
|
|
3267
3271
|
map.set(getName(member.name), {
|
|
3268
3272
|
type: ((_a = member.type) === null || _a === void 0 ? void 0 : _a.getText()) || 'Event',
|
|
@@ -3288,9 +3292,9 @@ class ComponentEventsFromEventsMap {
|
|
|
3288
3292
|
this.eventDispatcherImport = checkIfImportIsEventDispatcher(node);
|
|
3289
3293
|
}
|
|
3290
3294
|
checkIfIsStringLiteralDeclaration(node) {
|
|
3291
|
-
if (
|
|
3295
|
+
if (ts.isIdentifier(node.name) &&
|
|
3292
3296
|
node.initializer &&
|
|
3293
|
-
|
|
3297
|
+
ts.isStringLiteral(node.initializer)) {
|
|
3294
3298
|
this.stringVars.set(node.name.text, node.initializer.text);
|
|
3295
3299
|
}
|
|
3296
3300
|
}
|
|
@@ -3300,12 +3304,12 @@ class ComponentEventsFromEventsMap {
|
|
|
3300
3304
|
return;
|
|
3301
3305
|
}
|
|
3302
3306
|
const { dispatcherTyping, dispatcherName } = result;
|
|
3303
|
-
if (dispatcherTyping &&
|
|
3307
|
+
if (dispatcherTyping && ts.isTypeLiteralNode(dispatcherTyping)) {
|
|
3304
3308
|
this.eventDispatchers.push({
|
|
3305
3309
|
name: dispatcherName,
|
|
3306
3310
|
typing: dispatcherTyping.getText()
|
|
3307
3311
|
});
|
|
3308
|
-
dispatcherTyping.members.filter(
|
|
3312
|
+
dispatcherTyping.members.filter(ts.isPropertySignature).forEach((member) => {
|
|
3309
3313
|
var _a;
|
|
3310
3314
|
this.addToEvents(getName(member.name), {
|
|
3311
3315
|
type: `CustomEvent<${((_a = member.type) === null || _a === void 0 ? void 0 : _a.getText()) || 'any'}>`,
|
|
@@ -3325,14 +3329,14 @@ class ComponentEventsFromEventsMap {
|
|
|
3325
3329
|
}
|
|
3326
3330
|
checkIfCallExpressionIsDispatch(node) {
|
|
3327
3331
|
if (this.eventDispatchers.some((dispatcher) => !dispatcher.typing &&
|
|
3328
|
-
|
|
3332
|
+
ts.isIdentifier(node.expression) &&
|
|
3329
3333
|
node.expression.text === dispatcher.name)) {
|
|
3330
3334
|
const firstArg = node.arguments[0];
|
|
3331
|
-
if (
|
|
3335
|
+
if (ts.isStringLiteral(firstArg)) {
|
|
3332
3336
|
this.addToEvents(firstArg.text);
|
|
3333
3337
|
this.dispatchedEvents.add(firstArg.text);
|
|
3334
3338
|
}
|
|
3335
|
-
else if (
|
|
3339
|
+
else if (ts.isIdentifier(firstArg)) {
|
|
3336
3340
|
const str = this.stringVars.get(firstArg.text);
|
|
3337
3341
|
if (str) {
|
|
3338
3342
|
this.addToEvents(str);
|
|
@@ -3372,11 +3376,11 @@ class ComponentEventsFromEventsMap {
|
|
|
3372
3376
|
}
|
|
3373
3377
|
}
|
|
3374
3378
|
function getName(prop) {
|
|
3375
|
-
if (
|
|
3379
|
+
if (ts.isIdentifier(prop) || ts.isStringLiteral(prop)) {
|
|
3376
3380
|
return prop.text;
|
|
3377
3381
|
}
|
|
3378
|
-
if (
|
|
3379
|
-
if (
|
|
3382
|
+
if (ts.isComputedPropertyName(prop)) {
|
|
3383
|
+
if (ts.isIdentifier(prop.expression)) {
|
|
3380
3384
|
const identifierName = prop.expression.text;
|
|
3381
3385
|
const identifierValue = getIdentifierValue(prop, identifierName);
|
|
3382
3386
|
if (!identifierValue) {
|
|
@@ -3389,7 +3393,7 @@ function getName(prop) {
|
|
|
3389
3393
|
}
|
|
3390
3394
|
function getIdentifierValue(prop, identifierName) {
|
|
3391
3395
|
const variable = getVariableAtTopLevel(prop.getSourceFile(), identifierName);
|
|
3392
|
-
if (variable &&
|
|
3396
|
+
if (variable && ts.isStringLiteral(variable.initializer)) {
|
|
3393
3397
|
return variable.initializer.text;
|
|
3394
3398
|
}
|
|
3395
3399
|
}
|
|
@@ -3428,11 +3432,11 @@ function getDoc(member) {
|
|
|
3428
3432
|
}
|
|
3429
3433
|
function checkIfImportIsEventDispatcher(node) {
|
|
3430
3434
|
var _a;
|
|
3431
|
-
if (
|
|
3435
|
+
if (ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text !== 'svelte') {
|
|
3432
3436
|
return;
|
|
3433
3437
|
}
|
|
3434
3438
|
const namedImports = (_a = node.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings;
|
|
3435
|
-
if (namedImports &&
|
|
3439
|
+
if (namedImports && ts.isNamedImports(namedImports)) {
|
|
3436
3440
|
const eventDispatcherImport = namedImports.elements.find(
|
|
3437
3441
|
// If it's an aliased import, propertyName is set
|
|
3438
3442
|
(el) => (el.propertyName || el.name).text === 'createEventDispatcher');
|
|
@@ -3443,11 +3447,11 @@ function checkIfImportIsEventDispatcher(node) {
|
|
|
3443
3447
|
}
|
|
3444
3448
|
function checkIfDeclarationInstantiatedEventDispatcher(node, eventDispatcherImport) {
|
|
3445
3449
|
var _a;
|
|
3446
|
-
if (!
|
|
3450
|
+
if (!ts.isIdentifier(node.name) || !node.initializer) {
|
|
3447
3451
|
return;
|
|
3448
3452
|
}
|
|
3449
|
-
if (
|
|
3450
|
-
|
|
3453
|
+
if (ts.isCallExpression(node.initializer) &&
|
|
3454
|
+
ts.isIdentifier(node.initializer.expression) &&
|
|
3451
3455
|
node.initializer.expression.text === eventDispatcherImport) {
|
|
3452
3456
|
const dispatcherName = node.name.text;
|
|
3453
3457
|
const dispatcherTyping = (_a = node.initializer.typeArguments) === null || _a === void 0 ? void 0 : _a[0];
|
|
@@ -3670,14 +3674,28 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3670
3674
|
const load = exports.get('load');
|
|
3671
3675
|
if ((load === null || load === void 0 ? void 0 : load.type) === 'function' && load.node.parameters.length === 1 && !load.hasTypeDefinition) {
|
|
3672
3676
|
const pos = load.node.parameters[0].getEnd();
|
|
3673
|
-
const inserted = surround(`: import('./$types').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`);
|
|
3677
|
+
const inserted = surround(`: import('./$types.js').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`);
|
|
3674
3678
|
insert(pos, inserted);
|
|
3675
3679
|
}
|
|
3680
|
+
// add type to entries function if not explicitly typed
|
|
3681
|
+
const entries = exports.get('entries');
|
|
3682
|
+
if ((entries === null || entries === void 0 ? void 0 : entries.type) === 'function' &&
|
|
3683
|
+
entries.node.parameters.length === 0 &&
|
|
3684
|
+
!entries.hasTypeDefinition &&
|
|
3685
|
+
!basename.includes('layout')) {
|
|
3686
|
+
if (!entries.node.type && entries.node.body) {
|
|
3687
|
+
const returnPos = ts.isArrowFunction(entries.node)
|
|
3688
|
+
? entries.node.equalsGreaterThanToken.getStart()
|
|
3689
|
+
: entries.node.body.getStart();
|
|
3690
|
+
const returnInsertion = surround(`: ReturnType<import('./$types.js').EntryGenerator> `);
|
|
3691
|
+
insert(returnPos, returnInsertion);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3676
3694
|
// add type to actions variable if not explicitly typed
|
|
3677
3695
|
const actions = exports.get('actions');
|
|
3678
3696
|
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
3679
3697
|
const pos = actions.node.initializer.getEnd();
|
|
3680
|
-
const inserted = surround(` satisfies import('./$types').Actions`);
|
|
3698
|
+
const inserted = surround(` satisfies import('./$types.js').Actions`);
|
|
3681
3699
|
insert(pos, inserted);
|
|
3682
3700
|
}
|
|
3683
3701
|
addTypeToVariable(exports, surround, insert, 'prerender', `boolean | 'auto'`);
|
|
@@ -3686,7 +3704,7 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3686
3704
|
addTypeToVariable(exports, surround, insert, 'csr', `boolean`);
|
|
3687
3705
|
// add types to GET/PUT/POST/PATCH/DELETE/OPTIONS if not explicitly typed
|
|
3688
3706
|
const insertApiMethod = (name) => {
|
|
3689
|
-
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types').RequestEvent`, `Response | Promise<Response>`);
|
|
3707
|
+
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types.js').RequestEvent`, `Response | Promise<Response>`);
|
|
3690
3708
|
};
|
|
3691
3709
|
insertApiMethod('GET');
|
|
3692
3710
|
insertApiMethod('PUT');
|
|
@@ -3873,6 +3891,13 @@ function updatePrepends(str, index, toAppend, removeExisting) {
|
|
|
3873
3891
|
str.__prepends__.set(index, prepends);
|
|
3874
3892
|
return prepends;
|
|
3875
3893
|
}
|
|
3894
|
+
/**
|
|
3895
|
+
* Returns the prepends that were added at the given index (if any).
|
|
3896
|
+
*/
|
|
3897
|
+
function getCurrentPrepends(str, index) {
|
|
3898
|
+
var _a;
|
|
3899
|
+
return ((_a = str.__prepends__) === null || _a === void 0 ? void 0 : _a.get(index)) || [];
|
|
3900
|
+
}
|
|
3876
3901
|
|
|
3877
3902
|
function is$$PropsDeclaration(node) {
|
|
3878
3903
|
return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
|
|
@@ -3894,21 +3919,21 @@ class ExportedNames {
|
|
|
3894
3919
|
handleVariableStatement(node, parent) {
|
|
3895
3920
|
const exportModifier = findExportKeyword(node);
|
|
3896
3921
|
if (exportModifier) {
|
|
3897
|
-
const isLet = node.declarationList.flags ===
|
|
3898
|
-
const isConst = node.declarationList.flags ===
|
|
3922
|
+
const isLet = node.declarationList.flags === ts.NodeFlags.Let;
|
|
3923
|
+
const isConst = node.declarationList.flags === ts.NodeFlags.Const;
|
|
3899
3924
|
this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExport(...args));
|
|
3900
3925
|
if (isLet) {
|
|
3901
3926
|
this.propTypeAssertToUserDefined(node.declarationList);
|
|
3902
3927
|
}
|
|
3903
3928
|
else if (isConst) {
|
|
3904
3929
|
node.declarationList.forEachChild((n) => {
|
|
3905
|
-
if (
|
|
3930
|
+
if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name)) {
|
|
3906
3931
|
this.addGetter(n.name);
|
|
3907
|
-
const type = n.type ||
|
|
3932
|
+
const type = n.type || ts.getJSDocType(n);
|
|
3908
3933
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3909
3934
|
n.name.getText() === 'snapshot';
|
|
3910
3935
|
// TS types are not allowed in JS files, but TS will still pick it up and the ignore comment will filter out the error
|
|
3911
|
-
const kitType = isKitExport && !type ? `: import('./$types').Snapshot` : '';
|
|
3936
|
+
const kitType = isKitExport && !type ? `: import('./$types.js').Snapshot` : '';
|
|
3912
3937
|
const nameEnd = n.name.end + this.astOffset;
|
|
3913
3938
|
if (kitType) {
|
|
3914
3939
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
@@ -3918,7 +3943,7 @@ class ExportedNames {
|
|
|
3918
3943
|
}
|
|
3919
3944
|
this.removeExport(exportModifier.getStart(), exportModifier.end);
|
|
3920
3945
|
}
|
|
3921
|
-
else if (
|
|
3946
|
+
else if (ts.isSourceFile(parent)) {
|
|
3922
3947
|
this.handleExportedVariableDeclarationList(node.declarationList, this.addPossibleExport.bind(this));
|
|
3923
3948
|
}
|
|
3924
3949
|
}
|
|
@@ -3936,7 +3961,7 @@ class ExportedNames {
|
|
|
3936
3961
|
}
|
|
3937
3962
|
handleExportDeclaration(node) {
|
|
3938
3963
|
const { exportClause } = node;
|
|
3939
|
-
if (
|
|
3964
|
+
if (ts.isNamedExports(exportClause)) {
|
|
3940
3965
|
for (const ne of exportClause.elements) {
|
|
3941
3966
|
if (ne.propertyName) {
|
|
3942
3967
|
this.addExport(ne.propertyName, false, ne.name);
|
|
@@ -3966,14 +3991,14 @@ class ExportedNames {
|
|
|
3966
3991
|
const handleTypeAssertion = (declaration) => {
|
|
3967
3992
|
const identifier = declaration.name;
|
|
3968
3993
|
const tsType = declaration.type;
|
|
3969
|
-
const jsDocType =
|
|
3994
|
+
const jsDocType = ts.getJSDocType(declaration);
|
|
3970
3995
|
const type = tsType || jsDocType;
|
|
3971
3996
|
const name = identifier.getText();
|
|
3972
3997
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3973
3998
|
(name === 'data' || name === 'form' || name === 'snapshot');
|
|
3974
3999
|
// TS types are not allowed in JS files, but TS will still pick it up and the ignore comment will filter out the error
|
|
3975
4000
|
const kitType = isKitExport && !type
|
|
3976
|
-
? `: import('./$types').${name === 'data'
|
|
4001
|
+
? `: import('./$types.js').${name === 'data'
|
|
3977
4002
|
? this.basename.includes('layout')
|
|
3978
4003
|
? 'LayoutData'
|
|
3979
4004
|
: 'PageData'
|
|
@@ -3983,7 +4008,7 @@ class ExportedNames {
|
|
|
3983
4008
|
: '';
|
|
3984
4009
|
const nameEnd = identifier.end + this.astOffset;
|
|
3985
4010
|
const end = declaration.end + this.astOffset;
|
|
3986
|
-
if (
|
|
4011
|
+
if (ts.isIdentifier(identifier) &&
|
|
3987
4012
|
// Ensure initialization for proper control flow and to avoid "possibly undefined" type errors.
|
|
3988
4013
|
// Also ensure prop is typed as any with a type annotation in TS strict mode
|
|
3989
4014
|
(!declaration.initializer ||
|
|
@@ -3992,7 +4017,7 @@ class ExportedNames {
|
|
|
3992
4017
|
// Edge case: TS infers `export let bla = false` to type `false`.
|
|
3993
4018
|
// prevent that by adding the any-wrap in this case, too.
|
|
3994
4019
|
(!type &&
|
|
3995
|
-
[
|
|
4020
|
+
[ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(declaration.initializer.kind)))) {
|
|
3996
4021
|
const name = identifier.getText();
|
|
3997
4022
|
if (nameEnd === end) {
|
|
3998
4023
|
preprendStr(this.str, end, surroundWithIgnoreComments(`${kitType};${name} = __sveltets_2_any(${name});`));
|
|
@@ -4008,11 +4033,11 @@ class ExportedNames {
|
|
|
4008
4033
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
4009
4034
|
}
|
|
4010
4035
|
};
|
|
4011
|
-
const findComma = (target) => target.getChildren().filter((child) => child.kind ===
|
|
4036
|
+
const findComma = (target) => target.getChildren().filter((child) => child.kind === ts.SyntaxKind.CommaToken);
|
|
4012
4037
|
const splitDeclaration = () => {
|
|
4013
4038
|
const commas = node
|
|
4014
4039
|
.getChildren()
|
|
4015
|
-
.filter((child) => child.kind ===
|
|
4040
|
+
.filter((child) => child.kind === ts.SyntaxKind.SyntaxList)
|
|
4016
4041
|
.map(findComma)
|
|
4017
4042
|
.reduce((current, previous) => [...current, ...previous], []);
|
|
4018
4043
|
commas.forEach((comma) => {
|
|
@@ -4029,16 +4054,16 @@ class ExportedNames {
|
|
|
4029
4054
|
this.doneDeclarationTransformation.add(node);
|
|
4030
4055
|
}
|
|
4031
4056
|
handleExportedVariableDeclarationList(list, add) {
|
|
4032
|
-
const isLet = list.flags ===
|
|
4033
|
-
|
|
4034
|
-
if (
|
|
4035
|
-
if (
|
|
4057
|
+
const isLet = list.flags === ts.NodeFlags.Let;
|
|
4058
|
+
ts.forEachChild(list, (node) => {
|
|
4059
|
+
if (ts.isVariableDeclaration(node)) {
|
|
4060
|
+
if (ts.isIdentifier(node.name)) {
|
|
4036
4061
|
add(list, node.name, isLet, node.name, node.type, !node.initializer);
|
|
4037
4062
|
}
|
|
4038
|
-
else if (
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
if (
|
|
4063
|
+
else if (ts.isObjectBindingPattern(node.name) ||
|
|
4064
|
+
ts.isArrayBindingPattern(node.name)) {
|
|
4065
|
+
ts.forEachChild(node.name, (element) => {
|
|
4066
|
+
if (ts.isBindingElement(element)) {
|
|
4042
4067
|
add(list, element.name, isLet);
|
|
4043
4068
|
}
|
|
4044
4069
|
});
|
|
@@ -4079,10 +4104,10 @@ class ExportedNames {
|
|
|
4079
4104
|
* which could be exported through `export { .. }` later.
|
|
4080
4105
|
*/
|
|
4081
4106
|
addPossibleExport(declaration, name, isLet, target = null, type = null, required = false) {
|
|
4082
|
-
if (!
|
|
4107
|
+
if (!ts.isIdentifier(name)) {
|
|
4083
4108
|
return;
|
|
4084
4109
|
}
|
|
4085
|
-
if (target &&
|
|
4110
|
+
if (target && ts.isIdentifier(target)) {
|
|
4086
4111
|
this.possibleExports.set(name.text, {
|
|
4087
4112
|
declaration,
|
|
4088
4113
|
isLet,
|
|
@@ -4103,10 +4128,10 @@ class ExportedNames {
|
|
|
4103
4128
|
* Adds export to map
|
|
4104
4129
|
*/
|
|
4105
4130
|
addExport(name, isLet, target = null, type = null, required = false) {
|
|
4106
|
-
if (name.kind !=
|
|
4131
|
+
if (name.kind != ts.SyntaxKind.Identifier) {
|
|
4107
4132
|
throw Error('export source kind not supported ' + name);
|
|
4108
4133
|
}
|
|
4109
|
-
if (target && target.kind !=
|
|
4134
|
+
if (target && target.kind != ts.SyntaxKind.Identifier) {
|
|
4110
4135
|
throw Error('export target kind not supported ' + target);
|
|
4111
4136
|
}
|
|
4112
4137
|
const existingDeclaration = this.possibleExports.get(name.text);
|
|
@@ -4585,10 +4610,19 @@ class ImplicitStoreValues {
|
|
|
4585
4610
|
return;
|
|
4586
4611
|
}
|
|
4587
4612
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4588
|
-
const nodeEnd =
|
|
4613
|
+
const nodeEnd = ts.isVariableDeclarationList(node.parent) && node.parent.declarations.length > 1
|
|
4589
4614
|
? node.parent.declarations[node.parent.declarations.length - 1].getEnd()
|
|
4590
4615
|
: node.getEnd();
|
|
4591
|
-
|
|
4616
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1950
|
|
4617
|
+
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4618
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4619
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4620
|
+
if (getCurrentPrepends(str, nodeEnd + astOffset).length) {
|
|
4621
|
+
preprendStr(str, nodeEnd + astOffset, storeDeclarations);
|
|
4622
|
+
}
|
|
4623
|
+
else {
|
|
4624
|
+
str.appendRight(nodeEnd + astOffset, storeDeclarations);
|
|
4625
|
+
}
|
|
4592
4626
|
}
|
|
4593
4627
|
attachStoreValueDeclarationToReactiveAssignment(node, astOffset, str) {
|
|
4594
4628
|
const storeNames = getNamesFromLabeledStatement(node).filter((name) => this.accessedStores.has(name));
|
|
@@ -4597,9 +4631,10 @@ class ImplicitStoreValues {
|
|
|
4597
4631
|
}
|
|
4598
4632
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4599
4633
|
const endPos = node.getEnd() + astOffset;
|
|
4600
|
-
//
|
|
4634
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1097
|
|
4601
4635
|
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4602
|
-
// or investigate altering the inner workings of SourceMap
|
|
4636
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4637
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4603
4638
|
if (str.original.charAt(endPos - 1) !== ';') {
|
|
4604
4639
|
preprendStr(str, endPos, storeDeclarations);
|
|
4605
4640
|
}
|
|
@@ -5027,10 +5062,10 @@ class ImplicitTopLevelNames {
|
|
|
5027
5062
|
const start = expression.getStart() + this.astOffset;
|
|
5028
5063
|
const end = expression.getEnd() + this.astOffset;
|
|
5029
5064
|
// $: a = { .. }.. / $: a = .. as .. => () => ( .. )
|
|
5030
|
-
if (
|
|
5065
|
+
if (ts.isObjectLiteralExpression(expression) ||
|
|
5031
5066
|
(expression.getText().startsWith('{') &&
|
|
5032
5067
|
this.isNodeStartsWithObjectLiteral(expression)) ||
|
|
5033
|
-
|
|
5068
|
+
ts.isAsExpression(expression)) {
|
|
5034
5069
|
this.str.appendLeft(start, '(');
|
|
5035
5070
|
this.str.appendRight(end, ')');
|
|
5036
5071
|
}
|
|
@@ -5040,16 +5075,16 @@ class ImplicitTopLevelNames {
|
|
|
5040
5075
|
// in situations where there is a line break of ; guaranteed to be present (else the code is invalid)
|
|
5041
5076
|
}
|
|
5042
5077
|
isNodeStartsWithObjectLiteral(node) {
|
|
5043
|
-
if (
|
|
5078
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
5044
5079
|
return true;
|
|
5045
5080
|
}
|
|
5046
|
-
if (
|
|
5081
|
+
if (ts.isElementAccessExpression(node)) {
|
|
5047
5082
|
return this.isNodeStartsWithObjectLiteral(node.expression);
|
|
5048
5083
|
}
|
|
5049
|
-
if (
|
|
5084
|
+
if (ts.isBinaryExpression(node)) {
|
|
5050
5085
|
return this.isNodeStartsWithObjectLiteral(node.left);
|
|
5051
5086
|
}
|
|
5052
|
-
if (
|
|
5087
|
+
if (ts.isConditionalExpression(node)) {
|
|
5053
5088
|
return this.isNodeStartsWithObjectLiteral(node.condition);
|
|
5054
5089
|
}
|
|
5055
5090
|
return node
|
|
@@ -5085,7 +5120,7 @@ class ImplicitTopLevelNames {
|
|
|
5085
5120
|
// If expression is of type `$: ({a} = b);`,
|
|
5086
5121
|
// remove the surrounding braces so that the transformation
|
|
5087
5122
|
// to `let {a} = b;` produces valid code.
|
|
5088
|
-
if (
|
|
5123
|
+
if (ts.isExpressionStatement(node.statement) &&
|
|
5089
5124
|
isParenthesizedObjectOrArrayLiteralExpression(node.statement.expression)) {
|
|
5090
5125
|
const parenthesizedExpression = node.statement.expression;
|
|
5091
5126
|
const parenthesisStart = parenthesizedExpression.getStart() + this.astOffset;
|
|
@@ -5207,7 +5242,7 @@ class Generics {
|
|
|
5207
5242
|
}
|
|
5208
5243
|
addIfIsGeneric(node) {
|
|
5209
5244
|
var _a, _b;
|
|
5210
|
-
if (
|
|
5245
|
+
if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
|
|
5211
5246
|
if (((_a = node.type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
5212
5247
|
throw new Error('Invalid $$Generic declaration: Only one type argument allowed');
|
|
5213
5248
|
}
|
|
@@ -5224,13 +5259,13 @@ class Generics {
|
|
|
5224
5259
|
}
|
|
5225
5260
|
}
|
|
5226
5261
|
throwIfIsGeneric(node) {
|
|
5227
|
-
if (
|
|
5262
|
+
if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
|
|
5228
5263
|
throwError(this.astOffset + node.getStart(), this.astOffset + node.getEnd(), '$$Generic declarations are only allowed in the instance script', this.str.original);
|
|
5229
5264
|
}
|
|
5230
5265
|
}
|
|
5231
5266
|
is$$GenericType(node) {
|
|
5232
|
-
return (
|
|
5233
|
-
|
|
5267
|
+
return (ts.isTypeReferenceNode(node) &&
|
|
5268
|
+
ts.isIdentifier(node.typeName) &&
|
|
5234
5269
|
node.typeName.text === '$$Generic');
|
|
5235
5270
|
}
|
|
5236
5271
|
getTypeReferences() {
|
|
@@ -5261,13 +5296,13 @@ function handleImportDeclaration(node, str, astOffset, scriptStart, sourceFile)
|
|
|
5261
5296
|
function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
|
|
5262
5297
|
var _a;
|
|
5263
5298
|
const firstImport = tsAst.statements
|
|
5264
|
-
.filter(
|
|
5299
|
+
.filter(ts.isImportDeclaration)
|
|
5265
5300
|
.sort((a, b) => a.end - b.end)[0];
|
|
5266
5301
|
if (!firstImport) {
|
|
5267
5302
|
return;
|
|
5268
5303
|
}
|
|
5269
|
-
const firstComment = Array.from((_a =
|
|
5270
|
-
const start = firstComment && firstComment.kind ===
|
|
5304
|
+
const firstComment = Array.from((_a = ts.getLeadingCommentRanges(firstImport.getFullText(), 0)) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.pos - b.pos)[0];
|
|
5305
|
+
const start = firstComment && firstComment.kind === ts.SyntaxKind.MultiLineCommentTrivia
|
|
5271
5306
|
? firstComment.pos + firstImport.getFullStart()
|
|
5272
5307
|
: firstImport.getStart();
|
|
5273
5308
|
str.appendRight(start + astOffset, '\n' + (hasModuleScript ? '\n' : ''));
|
|
@@ -5417,13 +5452,11 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5417
5452
|
}
|
|
5418
5453
|
if (ts.isFunctionDeclaration(node)) {
|
|
5419
5454
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5420
|
-
pushScope();
|
|
5421
|
-
onLeaveCallbacks.push(() => popScope());
|
|
5422
5455
|
}
|
|
5423
5456
|
if (ts.isClassDeclaration(node)) {
|
|
5424
5457
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5425
5458
|
}
|
|
5426
|
-
if (ts.isBlock(node) || ts.
|
|
5459
|
+
if (ts.isBlock(node) || ts.isFunctionLike(node)) {
|
|
5427
5460
|
pushScope();
|
|
5428
5461
|
onLeaveCallbacks.push(() => popScope());
|
|
5429
5462
|
}
|
|
@@ -5556,7 +5589,7 @@ function transformInterfacesToTypes(tsAst, str, astOffset, movedNodes) {
|
|
|
5556
5589
|
function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
5557
5590
|
const htmlx = str.original;
|
|
5558
5591
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
5559
|
-
const tsAst =
|
|
5592
|
+
const tsAst = ts.createSourceFile('component.module.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
5560
5593
|
const astOffset = script.content.start;
|
|
5561
5594
|
const generics = new Generics(str, astOffset);
|
|
5562
5595
|
const walk = (node) => {
|
|
@@ -5565,7 +5598,7 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
|
5565
5598
|
throwIfIs$$EventsDeclaration(node, str, astOffset);
|
|
5566
5599
|
throwIfIs$$SlotsDeclaration(node, str, astOffset);
|
|
5567
5600
|
throwIfIs$$PropsDeclaration(node, str, astOffset);
|
|
5568
|
-
|
|
5601
|
+
ts.forEachChild(node, (n) => walk(n));
|
|
5569
5602
|
};
|
|
5570
5603
|
//walk the ast and convert to tsx as we go
|
|
5571
5604
|
tsAst.forEachChild((n) => walk(n));
|
|
@@ -5582,16 +5615,16 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
|
5582
5615
|
}
|
|
5583
5616
|
function resolveImplicitStoreValue(node, implicitStoreValues, str, astOffset) {
|
|
5584
5617
|
var _a;
|
|
5585
|
-
if (
|
|
5618
|
+
if (ts.isVariableDeclaration(node)) {
|
|
5586
5619
|
implicitStoreValues.addVariableDeclaration(node);
|
|
5587
5620
|
}
|
|
5588
|
-
if (
|
|
5621
|
+
if (ts.isImportClause(node)) {
|
|
5589
5622
|
implicitStoreValues.addImportStatement(node);
|
|
5590
5623
|
}
|
|
5591
|
-
if (
|
|
5624
|
+
if (ts.isImportSpecifier(node)) {
|
|
5592
5625
|
implicitStoreValues.addImportStatement(node);
|
|
5593
5626
|
}
|
|
5594
|
-
if ((_a =
|
|
5627
|
+
if ((_a = ts.isTypeAssertionExpression) === null || _a === void 0 ? void 0 : _a.call(ts, node)) {
|
|
5595
5628
|
handleTypeAssertion(str, node, astOffset);
|
|
5596
5629
|
}
|
|
5597
5630
|
}
|
|
@@ -5660,7 +5693,8 @@ class __sveltets_Render${genericsDef} {
|
|
|
5660
5693
|
}
|
|
5661
5694
|
else {
|
|
5662
5695
|
statement +=
|
|
5663
|
-
|
|
5696
|
+
'\n\nimport { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" \n' +
|
|
5697
|
+
`${doc}export default class${className ? ` ${className}` : ''}${genericsDef} extends __SvelteComponentTyped__<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> {` +
|
|
5664
5698
|
exportedNames.createClassGetters() +
|
|
5665
5699
|
(usesAccessors ? exportedNames.createClassAccessors() : '') +
|
|
5666
5700
|
'\n}';
|
|
@@ -6129,13 +6163,14 @@ async function emitDts(config) {
|
|
|
6129
6163
|
const svelteMap = await createSvelteMap(config);
|
|
6130
6164
|
const { options, filenames } = loadTsconfig(config, svelteMap);
|
|
6131
6165
|
const host = await createTsCompilerHost(options, svelteMap);
|
|
6132
|
-
const program =
|
|
6166
|
+
const program = ts.createProgram(filenames, options, host);
|
|
6133
6167
|
program.emit();
|
|
6134
6168
|
}
|
|
6135
6169
|
function loadTsconfig(config, svelteMap) {
|
|
6170
|
+
var _a;
|
|
6136
6171
|
const libRoot = config.libRoot || process.cwd();
|
|
6137
|
-
const jsconfigFile =
|
|
6138
|
-
let tsconfigFile =
|
|
6172
|
+
const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
|
|
6173
|
+
let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
|
|
6139
6174
|
if (!tsconfigFile && !jsconfigFile) {
|
|
6140
6175
|
throw new Error('Failed to locate tsconfig or jsconfig');
|
|
6141
6176
|
}
|
|
@@ -6145,7 +6180,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6145
6180
|
}
|
|
6146
6181
|
tsconfigFile = path.isAbsolute(tsconfigFile) ? tsconfigFile : path.join(libRoot, tsconfigFile);
|
|
6147
6182
|
const basepath = path.dirname(tsconfigFile);
|
|
6148
|
-
const { error, config: tsConfig } =
|
|
6183
|
+
const { error, config: tsConfig } = ts.readConfigFile(tsconfigFile, ts.sys.readFile);
|
|
6149
6184
|
if (error) {
|
|
6150
6185
|
throw new Error('Malformed tsconfig\n' + JSON.stringify(error, null, 2));
|
|
6151
6186
|
}
|
|
@@ -6157,7 +6192,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6157
6192
|
tsConfig.include = [`${libPathRelative}/**/*`];
|
|
6158
6193
|
tsConfig.files = [];
|
|
6159
6194
|
}
|
|
6160
|
-
const { options, fileNames } =
|
|
6195
|
+
const { options, fileNames } = ts.parseJsonConfigFileContent(tsConfig, ts.sys, basepath, { sourceMap: false, rootDir: config.libRoot }, tsconfigFile, undefined, [{ extension: 'svelte', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred }]);
|
|
6161
6196
|
const filenames = fileNames.map((name) => {
|
|
6162
6197
|
if (!isSvelteFilepath(name)) {
|
|
6163
6198
|
return name;
|
|
@@ -6175,7 +6210,9 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6175
6210
|
options: {
|
|
6176
6211
|
...options,
|
|
6177
6212
|
noEmit: false,
|
|
6178
|
-
moduleResolution:
|
|
6213
|
+
moduleResolution:
|
|
6214
|
+
// NodeJS: up to 4.9, Node10: since 5.0
|
|
6215
|
+
(_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10,
|
|
6179
6216
|
declaration: true,
|
|
6180
6217
|
emitDeclarationOnly: true,
|
|
6181
6218
|
declarationDir: config.declarationDir,
|
|
@@ -6185,7 +6222,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6185
6222
|
};
|
|
6186
6223
|
}
|
|
6187
6224
|
async function createTsCompilerHost(options, svelteMap) {
|
|
6188
|
-
const host =
|
|
6225
|
+
const host = ts.createCompilerHost(options);
|
|
6189
6226
|
// TypeScript writes the files relative to the found tsconfig/jsconfig
|
|
6190
6227
|
// which - at least in the case of the tests - is wrong. Therefore prefix
|
|
6191
6228
|
// the output paths. See Typescript issue #25430 for more.
|
|
@@ -6194,10 +6231,10 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6194
6231
|
.split(path.sep)
|
|
6195
6232
|
.join('/');
|
|
6196
6233
|
const svelteSys = {
|
|
6197
|
-
...
|
|
6234
|
+
...ts.sys,
|
|
6198
6235
|
fileExists(originalPath) {
|
|
6199
6236
|
const path = ensureRealSvelteFilepath(originalPath);
|
|
6200
|
-
const exists =
|
|
6237
|
+
const exists = ts.sys.fileExists(path);
|
|
6201
6238
|
if (exists && isSvelteFilepath(path)) {
|
|
6202
6239
|
const isTsFile = svelteMap.add(path);
|
|
6203
6240
|
if ((isTsFile && !isTsFilepath(originalPath)) ||
|
|
@@ -6213,12 +6250,12 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6213
6250
|
return svelteMap.get(path);
|
|
6214
6251
|
}
|
|
6215
6252
|
else {
|
|
6216
|
-
return
|
|
6253
|
+
return ts.sys.readFile(path, encoding);
|
|
6217
6254
|
}
|
|
6218
6255
|
},
|
|
6219
6256
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
6220
6257
|
const extensionsWithSvelte = (extensions || []).concat('.svelte');
|
|
6221
|
-
return
|
|
6258
|
+
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
|
|
6222
6259
|
},
|
|
6223
6260
|
writeFile(fileName, data, writeByteOrderMark) {
|
|
6224
6261
|
fileName = pathPrefix ? path.join(pathPrefix, fileName) : fileName;
|
|
@@ -6248,7 +6285,7 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6248
6285
|
return `"sources":["${sourcePath}"]`;
|
|
6249
6286
|
});
|
|
6250
6287
|
}
|
|
6251
|
-
return
|
|
6288
|
+
return ts.sys.writeFile(fileName, data, writeByteOrderMark);
|
|
6252
6289
|
}
|
|
6253
6290
|
};
|
|
6254
6291
|
host.fileExists = svelteSys.fileExists;
|
|
@@ -6260,7 +6297,6 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6260
6297
|
return resolveModuleName(moduleName, containingFile, compilerOptions);
|
|
6261
6298
|
});
|
|
6262
6299
|
};
|
|
6263
|
-
// @ts-expect-error remove once we bump dev dep to TS 5
|
|
6264
6300
|
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, _redirectedReference, compilerOptions) => {
|
|
6265
6301
|
return moduleLiterals.map((moduleLiteral) => {
|
|
6266
6302
|
return {
|
|
@@ -6272,11 +6308,11 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6272
6308
|
// Delegate to the TS resolver first.
|
|
6273
6309
|
// If that does not bring up anything, try the Svelte Module loader
|
|
6274
6310
|
// which is able to deal with .svelte files.
|
|
6275
|
-
const tsResolvedModule =
|
|
6311
|
+
const tsResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, ts.sys).resolvedModule;
|
|
6276
6312
|
if (tsResolvedModule && !isVirtualSvelteFilepath(tsResolvedModule.resolvedFileName)) {
|
|
6277
6313
|
return tsResolvedModule;
|
|
6278
6314
|
}
|
|
6279
|
-
return
|
|
6315
|
+
return ts.resolveModuleName(name, containingFile, compilerOptions, svelteSys)
|
|
6280
6316
|
.resolvedModule;
|
|
6281
6317
|
}
|
|
6282
6318
|
return host;
|
|
@@ -6290,7 +6326,7 @@ async function createSvelteMap(config) {
|
|
|
6290
6326
|
const svelteFiles = new Map();
|
|
6291
6327
|
function add(path) {
|
|
6292
6328
|
var _a, _b;
|
|
6293
|
-
const code =
|
|
6329
|
+
const code = ts.sys.readFile(path, 'utf-8');
|
|
6294
6330
|
const isTsFile = // svelte-preprocess allows default languages
|
|
6295
6331
|
['ts', 'typescript'].includes((_b = (_a = config.preprocess) === null || _a === void 0 ? void 0 : _a.defaultLanguages) === null || _b === void 0 ? void 0 : _b.script) ||
|
|
6296
6332
|
/<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte2tsx",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"description": "Convert Svelte components to TSX for type checking",
|
|
5
5
|
"author": "David Pershouse",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"rollup": "3.7.5",
|
|
35
35
|
"rollup-plugin-delete": "^2.0.0",
|
|
36
36
|
"source-map-support": "^0.5.16",
|
|
37
|
-
"svelte": "~3.
|
|
37
|
+
"svelte": "~3.57.0",
|
|
38
38
|
"tiny-glob": "^0.2.6",
|
|
39
39
|
"tslib": "^2.4.0",
|
|
40
|
-
"typescript": "^
|
|
40
|
+
"typescript": "^5.0.3"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"svelte": "^3.55",
|
package/svelte-shims.d.ts
CHANGED
|
@@ -60,12 +60,12 @@ declare class Svelte2TsxComponent<
|
|
|
60
60
|
$inject_state(): void;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/** @
|
|
63
|
+
/** @deprecated PRIVATE API, DO NOT USE, REMOVED SOON */
|
|
64
64
|
interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
|
|
65
65
|
/**
|
|
66
66
|
* An HTMLElement to render to. This option is required.
|
|
67
67
|
*/
|
|
68
|
-
target: Element | ShadowRoot;
|
|
68
|
+
target: Element | Document | ShadowRoot;
|
|
69
69
|
/**
|
|
70
70
|
* A child of `target` to render the component immediately before.
|
|
71
71
|
*/
|
|
@@ -82,7 +82,7 @@ interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
|
|
|
82
82
|
|
|
83
83
|
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
|
|
84
84
|
/** @internal PRIVATE API, DO NOT USE */
|
|
85
|
-
type SvelteComponentConstructor<T, U extends
|
|
85
|
+
type SvelteComponentConstructor<T, U extends import('svelte').ComponentConstructorOptions<any>> = new (options: U) => T;
|
|
86
86
|
|
|
87
87
|
/** @internal PRIVATE API, DO NOT USE */
|
|
88
88
|
type SvelteActionReturnType = {
|
|
@@ -207,7 +207,7 @@ declare function __sveltets_2_unionType(...types: any[]): any;
|
|
|
207
207
|
|
|
208
208
|
declare function __sveltets_2_createSvelte2TsxComponent<Props, Events, Slots>(
|
|
209
209
|
render: {props: Props, events: Events, slots: Slots }
|
|
210
|
-
): SvelteComponentConstructor<import("svelte").SvelteComponentTyped<Props, Events, Slots>,
|
|
210
|
+
): SvelteComponentConstructor<import("svelte").SvelteComponentTyped<Props, Events, Slots>,import('svelte').ComponentConstructorOptions<Props>>;
|
|
211
211
|
|
|
212
212
|
declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
|
|
213
213
|
declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
|