svelte2tsx 0.6.9 → 0.6.11
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 +74 -44
- package/index.mjs +160 -130
- package/package.json +4 -4
- 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,14 @@ 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
|
}
|
|
3696
3700
|
// add type to actions variable if not explicitly typed
|
|
3697
3701
|
const actions = exports.get('actions');
|
|
3698
3702
|
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
3699
3703
|
const pos = actions.node.initializer.getEnd();
|
|
3700
|
-
const inserted = surround(` satisfies import('./$types').Actions`);
|
|
3704
|
+
const inserted = surround(` satisfies import('./$types.js').Actions`);
|
|
3701
3705
|
insert(pos, inserted);
|
|
3702
3706
|
}
|
|
3703
3707
|
addTypeToVariable(exports, surround, insert, 'prerender', `boolean | 'auto'`);
|
|
@@ -3706,7 +3710,7 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3706
3710
|
addTypeToVariable(exports, surround, insert, 'csr', `boolean`);
|
|
3707
3711
|
// add types to GET/PUT/POST/PATCH/DELETE/OPTIONS if not explicitly typed
|
|
3708
3712
|
const insertApiMethod = (name) => {
|
|
3709
|
-
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types').RequestEvent`, `Response | Promise<Response>`);
|
|
3713
|
+
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types.js').RequestEvent`, `Response | Promise<Response>`);
|
|
3710
3714
|
};
|
|
3711
3715
|
insertApiMethod('GET');
|
|
3712
3716
|
insertApiMethod('PUT');
|
|
@@ -3893,6 +3897,13 @@ function updatePrepends(str, index, toAppend, removeExisting) {
|
|
|
3893
3897
|
str.__prepends__.set(index, prepends);
|
|
3894
3898
|
return prepends;
|
|
3895
3899
|
}
|
|
3900
|
+
/**
|
|
3901
|
+
* Returns the prepends that were added at the given index (if any).
|
|
3902
|
+
*/
|
|
3903
|
+
function getCurrentPrepends(str, index) {
|
|
3904
|
+
var _a;
|
|
3905
|
+
return ((_a = str.__prepends__) === null || _a === void 0 ? void 0 : _a.get(index)) || [];
|
|
3906
|
+
}
|
|
3896
3907
|
|
|
3897
3908
|
function is$$PropsDeclaration(node) {
|
|
3898
3909
|
return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
|
|
@@ -3928,7 +3939,7 @@ class ExportedNames {
|
|
|
3928
3939
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3929
3940
|
n.name.getText() === 'snapshot';
|
|
3930
3941
|
// 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` : '';
|
|
3942
|
+
const kitType = isKitExport && !type ? `: import('./$types.js').Snapshot` : '';
|
|
3932
3943
|
const nameEnd = n.name.end + this.astOffset;
|
|
3933
3944
|
if (kitType) {
|
|
3934
3945
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
@@ -3993,7 +4004,7 @@ class ExportedNames {
|
|
|
3993
4004
|
(name === 'data' || name === 'form' || name === 'snapshot');
|
|
3994
4005
|
// 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
4006
|
const kitType = isKitExport && !type
|
|
3996
|
-
? `: import('./$types').${name === 'data'
|
|
4007
|
+
? `: import('./$types.js').${name === 'data'
|
|
3997
4008
|
? this.basename.includes('layout')
|
|
3998
4009
|
? 'LayoutData'
|
|
3999
4010
|
: 'PageData'
|
|
@@ -4608,7 +4619,16 @@ class ImplicitStoreValues {
|
|
|
4608
4619
|
const nodeEnd = ts.isVariableDeclarationList(node.parent) && node.parent.declarations.length > 1
|
|
4609
4620
|
? node.parent.declarations[node.parent.declarations.length - 1].getEnd()
|
|
4610
4621
|
: node.getEnd();
|
|
4611
|
-
|
|
4622
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1950
|
|
4623
|
+
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4624
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4625
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4626
|
+
if (getCurrentPrepends(str, nodeEnd + astOffset).length) {
|
|
4627
|
+
preprendStr(str, nodeEnd + astOffset, storeDeclarations);
|
|
4628
|
+
}
|
|
4629
|
+
else {
|
|
4630
|
+
str.appendRight(nodeEnd + astOffset, storeDeclarations);
|
|
4631
|
+
}
|
|
4612
4632
|
}
|
|
4613
4633
|
attachStoreValueDeclarationToReactiveAssignment(node, astOffset, str) {
|
|
4614
4634
|
const storeNames = getNamesFromLabeledStatement(node).filter((name) => this.accessedStores.has(name));
|
|
@@ -4617,9 +4637,10 @@ class ImplicitStoreValues {
|
|
|
4617
4637
|
}
|
|
4618
4638
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4619
4639
|
const endPos = node.getEnd() + astOffset;
|
|
4620
|
-
//
|
|
4640
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1097
|
|
4621
4641
|
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4622
|
-
// or investigate altering the inner workings of SourceMap
|
|
4642
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4643
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4623
4644
|
if (str.original.charAt(endPos - 1) !== ';') {
|
|
4624
4645
|
preprendStr(str, endPos, storeDeclarations);
|
|
4625
4646
|
}
|
|
@@ -5346,7 +5367,7 @@ class InterfacesAndTypes {
|
|
|
5346
5367
|
function processInstanceScriptContent(str, script, events, implicitStoreValues, mode, hasModuleScript, basename) {
|
|
5347
5368
|
const htmlx = str.original;
|
|
5348
5369
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
5349
|
-
const tsAst =
|
|
5370
|
+
const tsAst = ts.createSourceFile('component.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
5350
5371
|
const astOffset = script.content.start;
|
|
5351
5372
|
const exportedNames = new ExportedNames(str, astOffset, basename);
|
|
5352
5373
|
const generics = new Generics(str, astOffset);
|
|
@@ -5391,12 +5412,12 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5391
5412
|
uses$$slots = true;
|
|
5392
5413
|
return;
|
|
5393
5414
|
}
|
|
5394
|
-
if (
|
|
5415
|
+
if (ts.isLabeledStatement(parent) && parent.label == ident) {
|
|
5395
5416
|
return;
|
|
5396
5417
|
}
|
|
5397
|
-
if (isDeclaration ||
|
|
5418
|
+
if (isDeclaration || ts.isParameter(parent)) {
|
|
5398
5419
|
if (isNotPropertyNameOfImport(ident) &&
|
|
5399
|
-
(!
|
|
5420
|
+
(!ts.isBindingElement(ident.parent) || ident.parent.name == ident)) {
|
|
5400
5421
|
// we are a key, not a name, so don't care
|
|
5401
5422
|
if (ident.text.startsWith('$') || scope == rootScope) {
|
|
5402
5423
|
// track all top level declared identifiers and all $ prefixed identifiers
|
|
@@ -5407,13 +5428,13 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5407
5428
|
else {
|
|
5408
5429
|
//track potential store usage to be resolved
|
|
5409
5430
|
if (ident.text.startsWith('$')) {
|
|
5410
|
-
if ((!
|
|
5411
|
-
(!
|
|
5412
|
-
!
|
|
5413
|
-
!
|
|
5414
|
-
!
|
|
5415
|
-
!
|
|
5416
|
-
!
|
|
5431
|
+
if ((!ts.isPropertyAccessExpression(parent) || parent.expression == ident) &&
|
|
5432
|
+
(!ts.isPropertyAssignment(parent) || parent.initializer == ident) &&
|
|
5433
|
+
!ts.isPropertySignature(parent) &&
|
|
5434
|
+
!ts.isPropertyDeclaration(parent) &&
|
|
5435
|
+
!ts.isTypeReferenceNode(parent) &&
|
|
5436
|
+
!ts.isTypeAliasDeclaration(parent) &&
|
|
5437
|
+
!ts.isInterfaceDeclaration(parent)) {
|
|
5417
5438
|
pendingStoreResolutions.push({ node: ident, parent, scope });
|
|
5418
5439
|
}
|
|
5419
5440
|
}
|
|
@@ -5432,71 +5453,69 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5432
5453
|
if (is$$PropsDeclaration(node)) {
|
|
5433
5454
|
exportedNames.uses$$Props = true;
|
|
5434
5455
|
}
|
|
5435
|
-
if (
|
|
5456
|
+
if (ts.isVariableStatement(node)) {
|
|
5436
5457
|
exportedNames.handleVariableStatement(node, parent);
|
|
5437
5458
|
}
|
|
5438
|
-
if (
|
|
5459
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
5439
5460
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5440
|
-
pushScope();
|
|
5441
|
-
onLeaveCallbacks.push(() => popScope());
|
|
5442
5461
|
}
|
|
5443
|
-
if (
|
|
5462
|
+
if (ts.isClassDeclaration(node)) {
|
|
5444
5463
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5445
5464
|
}
|
|
5446
|
-
if (
|
|
5465
|
+
if (ts.isBlock(node) || ts.isFunctionLike(node)) {
|
|
5447
5466
|
pushScope();
|
|
5448
5467
|
onLeaveCallbacks.push(() => popScope());
|
|
5449
5468
|
}
|
|
5450
|
-
if (
|
|
5469
|
+
if (ts.isExportDeclaration(node)) {
|
|
5451
5470
|
exportedNames.handleExportDeclaration(node);
|
|
5452
5471
|
}
|
|
5453
|
-
if (
|
|
5472
|
+
if (ts.isImportDeclaration(node)) {
|
|
5454
5473
|
handleImportDeclaration(node, str, astOffset, script.start, tsAst);
|
|
5455
5474
|
// Check if import is the event dispatcher
|
|
5456
5475
|
events.checkIfImportIsEventDispatcher(node);
|
|
5457
5476
|
}
|
|
5458
5477
|
// workaround for import statement completion
|
|
5459
|
-
if (
|
|
5478
|
+
if (ts.isImportEqualsDeclaration(node)) {
|
|
5460
5479
|
const end = node.getEnd() + astOffset;
|
|
5461
5480
|
if (str.original[end - 1] !== ';') {
|
|
5462
5481
|
preprendStr(str, end, ';');
|
|
5463
5482
|
}
|
|
5464
5483
|
}
|
|
5465
|
-
if (
|
|
5484
|
+
if (ts.isVariableDeclaration(node)) {
|
|
5466
5485
|
events.checkIfIsStringLiteralDeclaration(node);
|
|
5467
5486
|
events.checkIfDeclarationInstantiatedEventDispatcher(node);
|
|
5468
5487
|
implicitStoreValues.addVariableDeclaration(node);
|
|
5469
5488
|
}
|
|
5470
|
-
if (
|
|
5489
|
+
if (ts.isCallExpression(node)) {
|
|
5471
5490
|
events.checkIfCallExpressionIsDispatch(node);
|
|
5472
5491
|
}
|
|
5473
|
-
if (
|
|
5492
|
+
if (ts.isVariableDeclaration(parent) && parent.name == node) {
|
|
5474
5493
|
isDeclaration = true;
|
|
5475
5494
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5476
5495
|
}
|
|
5477
|
-
if (
|
|
5496
|
+
if (ts.isBindingElement(parent) && parent.name == node) {
|
|
5478
5497
|
isDeclaration = true;
|
|
5479
5498
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5480
5499
|
}
|
|
5481
|
-
if (
|
|
5500
|
+
if (ts.isImportClause(node)) {
|
|
5482
5501
|
isDeclaration = true;
|
|
5483
5502
|
onLeaveCallbacks.push(() => (isDeclaration = false));
|
|
5484
5503
|
implicitStoreValues.addImportStatement(node);
|
|
5485
5504
|
}
|
|
5486
|
-
if (
|
|
5505
|
+
if (ts.isImportSpecifier(node)) {
|
|
5487
5506
|
implicitStoreValues.addImportStatement(node);
|
|
5488
5507
|
}
|
|
5489
|
-
if (
|
|
5508
|
+
if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node)) {
|
|
5490
5509
|
interfacesAndTypes.node = node;
|
|
5491
5510
|
interfacesAndTypes.add(node);
|
|
5492
5511
|
onLeaveCallbacks.push(() => (interfacesAndTypes.node = null));
|
|
5493
5512
|
}
|
|
5494
5513
|
//handle stores etc
|
|
5495
|
-
if (
|
|
5514
|
+
if (ts.isIdentifier(node)) {
|
|
5496
5515
|
handleIdentifier(node, parent);
|
|
5497
5516
|
}
|
|
5498
5517
|
//track implicit declarations in reactive blocks at the top level
|
|
5499
|
-
if (
|
|
5518
|
+
if (ts.isLabeledStatement(node) &&
|
|
5500
5519
|
parent == tsAst && //top level
|
|
5501
5520
|
node.label.text == '$' &&
|
|
5502
5521
|
node.statement) {
|
|
@@ -5510,11 +5529,11 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5510
5529
|
// Defensively call function (checking for undefined) because it got added only recently (TS 4.0)
|
|
5511
5530
|
// and therefore might break people using older TS versions
|
|
5512
5531
|
// Don't transform in ts mode because <type>value type assertions are valid in this case
|
|
5513
|
-
if (mode !== 'ts' && ((_a =
|
|
5532
|
+
if (mode !== 'ts' && ((_a = ts.isTypeAssertionExpression) === null || _a === void 0 ? void 0 : _a.call(ts, node))) {
|
|
5514
5533
|
handleTypeAssertion(str, node, astOffset);
|
|
5515
5534
|
}
|
|
5516
5535
|
//to save a bunch of condition checks on each node, we recurse into processChild which skips all the checks for top level items
|
|
5517
|
-
|
|
5536
|
+
ts.forEachChild(node, (n) => walk(n, node));
|
|
5518
5537
|
//fire off the on leave callbacks
|
|
5519
5538
|
onLeaveCallbacks.map((c) => c());
|
|
5520
5539
|
};
|
|
@@ -5551,7 +5570,7 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5551
5570
|
}
|
|
5552
5571
|
function transformInterfacesToTypes(tsAst, str, astOffset, movedNodes) {
|
|
5553
5572
|
tsAst.statements
|
|
5554
|
-
.filter(
|
|
5573
|
+
.filter(ts.isInterfaceDeclaration)
|
|
5555
5574
|
.filter((i) => !movedNodes.includes(i))
|
|
5556
5575
|
.forEach((node) => {
|
|
5557
5576
|
var _a;
|
|
@@ -5680,7 +5699,8 @@ class __sveltets_Render${genericsDef} {
|
|
|
5680
5699
|
}
|
|
5681
5700
|
else {
|
|
5682
5701
|
statement +=
|
|
5683
|
-
|
|
5702
|
+
'\n\nimport { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" \n' +
|
|
5703
|
+
`${doc}export default class${className ? ` ${className}` : ''}${genericsDef} extends __SvelteComponentTyped__<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> {` +
|
|
5684
5704
|
exportedNames.createClassGetters() +
|
|
5685
5705
|
(usesAccessors ? exportedNames.createClassAccessors() : '') +
|
|
5686
5706
|
'\n}';
|
|
@@ -6153,6 +6173,7 @@ async function emitDts(config) {
|
|
|
6153
6173
|
program.emit();
|
|
6154
6174
|
}
|
|
6155
6175
|
function loadTsconfig(config, svelteMap) {
|
|
6176
|
+
var _a;
|
|
6156
6177
|
const libRoot = config.libRoot || process.cwd();
|
|
6157
6178
|
const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
|
|
6158
6179
|
let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
|
|
@@ -6195,7 +6216,9 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6195
6216
|
options: {
|
|
6196
6217
|
...options,
|
|
6197
6218
|
noEmit: false,
|
|
6198
|
-
moduleResolution:
|
|
6219
|
+
moduleResolution:
|
|
6220
|
+
// NodeJS: up to 4.9, Node10: since 5.0
|
|
6221
|
+
(_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10,
|
|
6199
6222
|
declaration: true,
|
|
6200
6223
|
emitDeclarationOnly: true,
|
|
6201
6224
|
declarationDir: config.declarationDir,
|
|
@@ -6280,6 +6303,13 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6280
6303
|
return resolveModuleName(moduleName, containingFile, compilerOptions);
|
|
6281
6304
|
});
|
|
6282
6305
|
};
|
|
6306
|
+
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, _redirectedReference, compilerOptions) => {
|
|
6307
|
+
return moduleLiterals.map((moduleLiteral) => {
|
|
6308
|
+
return {
|
|
6309
|
+
resolvedModule: resolveModuleName(moduleLiteral.text, containingFile, compilerOptions)
|
|
6310
|
+
};
|
|
6311
|
+
});
|
|
6312
|
+
};
|
|
6283
6313
|
function resolveModuleName(name, containingFile, compilerOptions) {
|
|
6284
6314
|
// Delegate to the TS resolver first.
|
|
6285
6315
|
// If that does not bring up anything, try the Svelte Module loader
|
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,14 @@ 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
|
}
|
|
3676
3680
|
// add type to actions variable if not explicitly typed
|
|
3677
3681
|
const actions = exports.get('actions');
|
|
3678
3682
|
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
3679
3683
|
const pos = actions.node.initializer.getEnd();
|
|
3680
|
-
const inserted = surround(` satisfies import('./$types').Actions`);
|
|
3684
|
+
const inserted = surround(` satisfies import('./$types.js').Actions`);
|
|
3681
3685
|
insert(pos, inserted);
|
|
3682
3686
|
}
|
|
3683
3687
|
addTypeToVariable(exports, surround, insert, 'prerender', `boolean | 'auto'`);
|
|
@@ -3686,7 +3690,7 @@ function upserKitRouteFile(ts, basename, getSource, surround) {
|
|
|
3686
3690
|
addTypeToVariable(exports, surround, insert, 'csr', `boolean`);
|
|
3687
3691
|
// add types to GET/PUT/POST/PATCH/DELETE/OPTIONS if not explicitly typed
|
|
3688
3692
|
const insertApiMethod = (name) => {
|
|
3689
|
-
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types').RequestEvent`, `Response | Promise<Response>`);
|
|
3693
|
+
addTypeToFunction(ts, exports, surround, insert, name, `import('./$types.js').RequestEvent`, `Response | Promise<Response>`);
|
|
3690
3694
|
};
|
|
3691
3695
|
insertApiMethod('GET');
|
|
3692
3696
|
insertApiMethod('PUT');
|
|
@@ -3873,6 +3877,13 @@ function updatePrepends(str, index, toAppend, removeExisting) {
|
|
|
3873
3877
|
str.__prepends__.set(index, prepends);
|
|
3874
3878
|
return prepends;
|
|
3875
3879
|
}
|
|
3880
|
+
/**
|
|
3881
|
+
* Returns the prepends that were added at the given index (if any).
|
|
3882
|
+
*/
|
|
3883
|
+
function getCurrentPrepends(str, index) {
|
|
3884
|
+
var _a;
|
|
3885
|
+
return ((_a = str.__prepends__) === null || _a === void 0 ? void 0 : _a.get(index)) || [];
|
|
3886
|
+
}
|
|
3876
3887
|
|
|
3877
3888
|
function is$$PropsDeclaration(node) {
|
|
3878
3889
|
return isInterfaceOrTypeDeclaration(node) && node.name.text === '$$Props';
|
|
@@ -3894,21 +3905,21 @@ class ExportedNames {
|
|
|
3894
3905
|
handleVariableStatement(node, parent) {
|
|
3895
3906
|
const exportModifier = findExportKeyword(node);
|
|
3896
3907
|
if (exportModifier) {
|
|
3897
|
-
const isLet = node.declarationList.flags ===
|
|
3898
|
-
const isConst = node.declarationList.flags ===
|
|
3908
|
+
const isLet = node.declarationList.flags === ts.NodeFlags.Let;
|
|
3909
|
+
const isConst = node.declarationList.flags === ts.NodeFlags.Const;
|
|
3899
3910
|
this.handleExportedVariableDeclarationList(node.declarationList, (_, ...args) => this.addExport(...args));
|
|
3900
3911
|
if (isLet) {
|
|
3901
3912
|
this.propTypeAssertToUserDefined(node.declarationList);
|
|
3902
3913
|
}
|
|
3903
3914
|
else if (isConst) {
|
|
3904
3915
|
node.declarationList.forEachChild((n) => {
|
|
3905
|
-
if (
|
|
3916
|
+
if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name)) {
|
|
3906
3917
|
this.addGetter(n.name);
|
|
3907
|
-
const type = n.type ||
|
|
3918
|
+
const type = n.type || ts.getJSDocType(n);
|
|
3908
3919
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3909
3920
|
n.name.getText() === 'snapshot';
|
|
3910
3921
|
// 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` : '';
|
|
3922
|
+
const kitType = isKitExport && !type ? `: import('./$types.js').Snapshot` : '';
|
|
3912
3923
|
const nameEnd = n.name.end + this.astOffset;
|
|
3913
3924
|
if (kitType) {
|
|
3914
3925
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
@@ -3918,7 +3929,7 @@ class ExportedNames {
|
|
|
3918
3929
|
}
|
|
3919
3930
|
this.removeExport(exportModifier.getStart(), exportModifier.end);
|
|
3920
3931
|
}
|
|
3921
|
-
else if (
|
|
3932
|
+
else if (ts.isSourceFile(parent)) {
|
|
3922
3933
|
this.handleExportedVariableDeclarationList(node.declarationList, this.addPossibleExport.bind(this));
|
|
3923
3934
|
}
|
|
3924
3935
|
}
|
|
@@ -3936,7 +3947,7 @@ class ExportedNames {
|
|
|
3936
3947
|
}
|
|
3937
3948
|
handleExportDeclaration(node) {
|
|
3938
3949
|
const { exportClause } = node;
|
|
3939
|
-
if (
|
|
3950
|
+
if (ts.isNamedExports(exportClause)) {
|
|
3940
3951
|
for (const ne of exportClause.elements) {
|
|
3941
3952
|
if (ne.propertyName) {
|
|
3942
3953
|
this.addExport(ne.propertyName, false, ne.name);
|
|
@@ -3966,14 +3977,14 @@ class ExportedNames {
|
|
|
3966
3977
|
const handleTypeAssertion = (declaration) => {
|
|
3967
3978
|
const identifier = declaration.name;
|
|
3968
3979
|
const tsType = declaration.type;
|
|
3969
|
-
const jsDocType =
|
|
3980
|
+
const jsDocType = ts.getJSDocType(declaration);
|
|
3970
3981
|
const type = tsType || jsDocType;
|
|
3971
3982
|
const name = identifier.getText();
|
|
3972
3983
|
const isKitExport = internalHelpers.isKitRouteFile(this.basename) &&
|
|
3973
3984
|
(name === 'data' || name === 'form' || name === 'snapshot');
|
|
3974
3985
|
// 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
3986
|
const kitType = isKitExport && !type
|
|
3976
|
-
? `: import('./$types').${name === 'data'
|
|
3987
|
+
? `: import('./$types.js').${name === 'data'
|
|
3977
3988
|
? this.basename.includes('layout')
|
|
3978
3989
|
? 'LayoutData'
|
|
3979
3990
|
: 'PageData'
|
|
@@ -3983,7 +3994,7 @@ class ExportedNames {
|
|
|
3983
3994
|
: '';
|
|
3984
3995
|
const nameEnd = identifier.end + this.astOffset;
|
|
3985
3996
|
const end = declaration.end + this.astOffset;
|
|
3986
|
-
if (
|
|
3997
|
+
if (ts.isIdentifier(identifier) &&
|
|
3987
3998
|
// Ensure initialization for proper control flow and to avoid "possibly undefined" type errors.
|
|
3988
3999
|
// Also ensure prop is typed as any with a type annotation in TS strict mode
|
|
3989
4000
|
(!declaration.initializer ||
|
|
@@ -3992,7 +4003,7 @@ class ExportedNames {
|
|
|
3992
4003
|
// Edge case: TS infers `export let bla = false` to type `false`.
|
|
3993
4004
|
// prevent that by adding the any-wrap in this case, too.
|
|
3994
4005
|
(!type &&
|
|
3995
|
-
[
|
|
4006
|
+
[ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(declaration.initializer.kind)))) {
|
|
3996
4007
|
const name = identifier.getText();
|
|
3997
4008
|
if (nameEnd === end) {
|
|
3998
4009
|
preprendStr(this.str, end, surroundWithIgnoreComments(`${kitType};${name} = __sveltets_2_any(${name});`));
|
|
@@ -4008,11 +4019,11 @@ class ExportedNames {
|
|
|
4008
4019
|
preprendStr(this.str, nameEnd, surroundWithIgnoreComments(kitType));
|
|
4009
4020
|
}
|
|
4010
4021
|
};
|
|
4011
|
-
const findComma = (target) => target.getChildren().filter((child) => child.kind ===
|
|
4022
|
+
const findComma = (target) => target.getChildren().filter((child) => child.kind === ts.SyntaxKind.CommaToken);
|
|
4012
4023
|
const splitDeclaration = () => {
|
|
4013
4024
|
const commas = node
|
|
4014
4025
|
.getChildren()
|
|
4015
|
-
.filter((child) => child.kind ===
|
|
4026
|
+
.filter((child) => child.kind === ts.SyntaxKind.SyntaxList)
|
|
4016
4027
|
.map(findComma)
|
|
4017
4028
|
.reduce((current, previous) => [...current, ...previous], []);
|
|
4018
4029
|
commas.forEach((comma) => {
|
|
@@ -4029,16 +4040,16 @@ class ExportedNames {
|
|
|
4029
4040
|
this.doneDeclarationTransformation.add(node);
|
|
4030
4041
|
}
|
|
4031
4042
|
handleExportedVariableDeclarationList(list, add) {
|
|
4032
|
-
const isLet = list.flags ===
|
|
4033
|
-
|
|
4034
|
-
if (
|
|
4035
|
-
if (
|
|
4043
|
+
const isLet = list.flags === ts.NodeFlags.Let;
|
|
4044
|
+
ts.forEachChild(list, (node) => {
|
|
4045
|
+
if (ts.isVariableDeclaration(node)) {
|
|
4046
|
+
if (ts.isIdentifier(node.name)) {
|
|
4036
4047
|
add(list, node.name, isLet, node.name, node.type, !node.initializer);
|
|
4037
4048
|
}
|
|
4038
|
-
else if (
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
if (
|
|
4049
|
+
else if (ts.isObjectBindingPattern(node.name) ||
|
|
4050
|
+
ts.isArrayBindingPattern(node.name)) {
|
|
4051
|
+
ts.forEachChild(node.name, (element) => {
|
|
4052
|
+
if (ts.isBindingElement(element)) {
|
|
4042
4053
|
add(list, element.name, isLet);
|
|
4043
4054
|
}
|
|
4044
4055
|
});
|
|
@@ -4079,10 +4090,10 @@ class ExportedNames {
|
|
|
4079
4090
|
* which could be exported through `export { .. }` later.
|
|
4080
4091
|
*/
|
|
4081
4092
|
addPossibleExport(declaration, name, isLet, target = null, type = null, required = false) {
|
|
4082
|
-
if (!
|
|
4093
|
+
if (!ts.isIdentifier(name)) {
|
|
4083
4094
|
return;
|
|
4084
4095
|
}
|
|
4085
|
-
if (target &&
|
|
4096
|
+
if (target && ts.isIdentifier(target)) {
|
|
4086
4097
|
this.possibleExports.set(name.text, {
|
|
4087
4098
|
declaration,
|
|
4088
4099
|
isLet,
|
|
@@ -4103,10 +4114,10 @@ class ExportedNames {
|
|
|
4103
4114
|
* Adds export to map
|
|
4104
4115
|
*/
|
|
4105
4116
|
addExport(name, isLet, target = null, type = null, required = false) {
|
|
4106
|
-
if (name.kind !=
|
|
4117
|
+
if (name.kind != ts.SyntaxKind.Identifier) {
|
|
4107
4118
|
throw Error('export source kind not supported ' + name);
|
|
4108
4119
|
}
|
|
4109
|
-
if (target && target.kind !=
|
|
4120
|
+
if (target && target.kind != ts.SyntaxKind.Identifier) {
|
|
4110
4121
|
throw Error('export target kind not supported ' + target);
|
|
4111
4122
|
}
|
|
4112
4123
|
const existingDeclaration = this.possibleExports.get(name.text);
|
|
@@ -4585,10 +4596,19 @@ class ImplicitStoreValues {
|
|
|
4585
4596
|
return;
|
|
4586
4597
|
}
|
|
4587
4598
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4588
|
-
const nodeEnd =
|
|
4599
|
+
const nodeEnd = ts.isVariableDeclarationList(node.parent) && node.parent.declarations.length > 1
|
|
4589
4600
|
? node.parent.declarations[node.parent.declarations.length - 1].getEnd()
|
|
4590
4601
|
: node.getEnd();
|
|
4591
|
-
|
|
4602
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1950
|
|
4603
|
+
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4604
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4605
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4606
|
+
if (getCurrentPrepends(str, nodeEnd + astOffset).length) {
|
|
4607
|
+
preprendStr(str, nodeEnd + astOffset, storeDeclarations);
|
|
4608
|
+
}
|
|
4609
|
+
else {
|
|
4610
|
+
str.appendRight(nodeEnd + astOffset, storeDeclarations);
|
|
4611
|
+
}
|
|
4592
4612
|
}
|
|
4593
4613
|
attachStoreValueDeclarationToReactiveAssignment(node, astOffset, str) {
|
|
4594
4614
|
const storeNames = getNamesFromLabeledStatement(node).filter((name) => this.accessedStores.has(name));
|
|
@@ -4597,9 +4617,10 @@ class ImplicitStoreValues {
|
|
|
4597
4617
|
}
|
|
4598
4618
|
const storeDeclarations = surroundWithIgnoreComments(this.createStoreDeclarations(storeNames));
|
|
4599
4619
|
const endPos = node.getEnd() + astOffset;
|
|
4600
|
-
//
|
|
4620
|
+
// Quick-fixing https://github.com/sveltejs/language-tools/issues/1097
|
|
4601
4621
|
// TODO think about a SourceMap-wrapper that does these things for us,
|
|
4602
|
-
// or investigate altering the inner workings of SourceMap
|
|
4622
|
+
// or investigate altering the inner workings of SourceMap, or investigate
|
|
4623
|
+
// if we can always use prependStr here (and elsewhere, too)
|
|
4603
4624
|
if (str.original.charAt(endPos - 1) !== ';') {
|
|
4604
4625
|
preprendStr(str, endPos, storeDeclarations);
|
|
4605
4626
|
}
|
|
@@ -5027,10 +5048,10 @@ class ImplicitTopLevelNames {
|
|
|
5027
5048
|
const start = expression.getStart() + this.astOffset;
|
|
5028
5049
|
const end = expression.getEnd() + this.astOffset;
|
|
5029
5050
|
// $: a = { .. }.. / $: a = .. as .. => () => ( .. )
|
|
5030
|
-
if (
|
|
5051
|
+
if (ts.isObjectLiteralExpression(expression) ||
|
|
5031
5052
|
(expression.getText().startsWith('{') &&
|
|
5032
5053
|
this.isNodeStartsWithObjectLiteral(expression)) ||
|
|
5033
|
-
|
|
5054
|
+
ts.isAsExpression(expression)) {
|
|
5034
5055
|
this.str.appendLeft(start, '(');
|
|
5035
5056
|
this.str.appendRight(end, ')');
|
|
5036
5057
|
}
|
|
@@ -5040,16 +5061,16 @@ class ImplicitTopLevelNames {
|
|
|
5040
5061
|
// in situations where there is a line break of ; guaranteed to be present (else the code is invalid)
|
|
5041
5062
|
}
|
|
5042
5063
|
isNodeStartsWithObjectLiteral(node) {
|
|
5043
|
-
if (
|
|
5064
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
5044
5065
|
return true;
|
|
5045
5066
|
}
|
|
5046
|
-
if (
|
|
5067
|
+
if (ts.isElementAccessExpression(node)) {
|
|
5047
5068
|
return this.isNodeStartsWithObjectLiteral(node.expression);
|
|
5048
5069
|
}
|
|
5049
|
-
if (
|
|
5070
|
+
if (ts.isBinaryExpression(node)) {
|
|
5050
5071
|
return this.isNodeStartsWithObjectLiteral(node.left);
|
|
5051
5072
|
}
|
|
5052
|
-
if (
|
|
5073
|
+
if (ts.isConditionalExpression(node)) {
|
|
5053
5074
|
return this.isNodeStartsWithObjectLiteral(node.condition);
|
|
5054
5075
|
}
|
|
5055
5076
|
return node
|
|
@@ -5085,7 +5106,7 @@ class ImplicitTopLevelNames {
|
|
|
5085
5106
|
// If expression is of type `$: ({a} = b);`,
|
|
5086
5107
|
// remove the surrounding braces so that the transformation
|
|
5087
5108
|
// to `let {a} = b;` produces valid code.
|
|
5088
|
-
if (
|
|
5109
|
+
if (ts.isExpressionStatement(node.statement) &&
|
|
5089
5110
|
isParenthesizedObjectOrArrayLiteralExpression(node.statement.expression)) {
|
|
5090
5111
|
const parenthesizedExpression = node.statement.expression;
|
|
5091
5112
|
const parenthesisStart = parenthesizedExpression.getStart() + this.astOffset;
|
|
@@ -5207,7 +5228,7 @@ class Generics {
|
|
|
5207
5228
|
}
|
|
5208
5229
|
addIfIsGeneric(node) {
|
|
5209
5230
|
var _a, _b;
|
|
5210
|
-
if (
|
|
5231
|
+
if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
|
|
5211
5232
|
if (((_a = node.type.typeArguments) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
5212
5233
|
throw new Error('Invalid $$Generic declaration: Only one type argument allowed');
|
|
5213
5234
|
}
|
|
@@ -5224,13 +5245,13 @@ class Generics {
|
|
|
5224
5245
|
}
|
|
5225
5246
|
}
|
|
5226
5247
|
throwIfIsGeneric(node) {
|
|
5227
|
-
if (
|
|
5248
|
+
if (ts.isTypeAliasDeclaration(node) && this.is$$GenericType(node.type)) {
|
|
5228
5249
|
throwError(this.astOffset + node.getStart(), this.astOffset + node.getEnd(), '$$Generic declarations are only allowed in the instance script', this.str.original);
|
|
5229
5250
|
}
|
|
5230
5251
|
}
|
|
5231
5252
|
is$$GenericType(node) {
|
|
5232
|
-
return (
|
|
5233
|
-
|
|
5253
|
+
return (ts.isTypeReferenceNode(node) &&
|
|
5254
|
+
ts.isIdentifier(node.typeName) &&
|
|
5234
5255
|
node.typeName.text === '$$Generic');
|
|
5235
5256
|
}
|
|
5236
5257
|
getTypeReferences() {
|
|
@@ -5261,13 +5282,13 @@ function handleImportDeclaration(node, str, astOffset, scriptStart, sourceFile)
|
|
|
5261
5282
|
function handleFirstInstanceImport(tsAst, astOffset, hasModuleScript, str) {
|
|
5262
5283
|
var _a;
|
|
5263
5284
|
const firstImport = tsAst.statements
|
|
5264
|
-
.filter(
|
|
5285
|
+
.filter(ts.isImportDeclaration)
|
|
5265
5286
|
.sort((a, b) => a.end - b.end)[0];
|
|
5266
5287
|
if (!firstImport) {
|
|
5267
5288
|
return;
|
|
5268
5289
|
}
|
|
5269
|
-
const firstComment = Array.from((_a =
|
|
5270
|
-
const start = firstComment && firstComment.kind ===
|
|
5290
|
+
const firstComment = Array.from((_a = ts.getLeadingCommentRanges(firstImport.getFullText(), 0)) !== null && _a !== void 0 ? _a : []).sort((a, b) => a.pos - b.pos)[0];
|
|
5291
|
+
const start = firstComment && firstComment.kind === ts.SyntaxKind.MultiLineCommentTrivia
|
|
5271
5292
|
? firstComment.pos + firstImport.getFullStart()
|
|
5272
5293
|
: firstImport.getStart();
|
|
5273
5294
|
str.appendRight(start + astOffset, '\n' + (hasModuleScript ? '\n' : ''));
|
|
@@ -5417,13 +5438,11 @@ function processInstanceScriptContent(str, script, events, implicitStoreValues,
|
|
|
5417
5438
|
}
|
|
5418
5439
|
if (ts.isFunctionDeclaration(node)) {
|
|
5419
5440
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5420
|
-
pushScope();
|
|
5421
|
-
onLeaveCallbacks.push(() => popScope());
|
|
5422
5441
|
}
|
|
5423
5442
|
if (ts.isClassDeclaration(node)) {
|
|
5424
5443
|
exportedNames.handleExportFunctionOrClass(node);
|
|
5425
5444
|
}
|
|
5426
|
-
if (ts.isBlock(node) || ts.
|
|
5445
|
+
if (ts.isBlock(node) || ts.isFunctionLike(node)) {
|
|
5427
5446
|
pushScope();
|
|
5428
5447
|
onLeaveCallbacks.push(() => popScope());
|
|
5429
5448
|
}
|
|
@@ -5556,7 +5575,7 @@ function transformInterfacesToTypes(tsAst, str, astOffset, movedNodes) {
|
|
|
5556
5575
|
function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
5557
5576
|
const htmlx = str.original;
|
|
5558
5577
|
const scriptContent = htmlx.substring(script.content.start, script.content.end);
|
|
5559
|
-
const tsAst =
|
|
5578
|
+
const tsAst = ts.createSourceFile('component.module.ts.svelte', scriptContent, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
5560
5579
|
const astOffset = script.content.start;
|
|
5561
5580
|
const generics = new Generics(str, astOffset);
|
|
5562
5581
|
const walk = (node) => {
|
|
@@ -5565,7 +5584,7 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
|
5565
5584
|
throwIfIs$$EventsDeclaration(node, str, astOffset);
|
|
5566
5585
|
throwIfIs$$SlotsDeclaration(node, str, astOffset);
|
|
5567
5586
|
throwIfIs$$PropsDeclaration(node, str, astOffset);
|
|
5568
|
-
|
|
5587
|
+
ts.forEachChild(node, (n) => walk(n));
|
|
5569
5588
|
};
|
|
5570
5589
|
//walk the ast and convert to tsx as we go
|
|
5571
5590
|
tsAst.forEachChild((n) => walk(n));
|
|
@@ -5582,16 +5601,16 @@ function processModuleScriptTag(str, script, implicitStoreValues) {
|
|
|
5582
5601
|
}
|
|
5583
5602
|
function resolveImplicitStoreValue(node, implicitStoreValues, str, astOffset) {
|
|
5584
5603
|
var _a;
|
|
5585
|
-
if (
|
|
5604
|
+
if (ts.isVariableDeclaration(node)) {
|
|
5586
5605
|
implicitStoreValues.addVariableDeclaration(node);
|
|
5587
5606
|
}
|
|
5588
|
-
if (
|
|
5607
|
+
if (ts.isImportClause(node)) {
|
|
5589
5608
|
implicitStoreValues.addImportStatement(node);
|
|
5590
5609
|
}
|
|
5591
|
-
if (
|
|
5610
|
+
if (ts.isImportSpecifier(node)) {
|
|
5592
5611
|
implicitStoreValues.addImportStatement(node);
|
|
5593
5612
|
}
|
|
5594
|
-
if ((_a =
|
|
5613
|
+
if ((_a = ts.isTypeAssertionExpression) === null || _a === void 0 ? void 0 : _a.call(ts, node)) {
|
|
5595
5614
|
handleTypeAssertion(str, node, astOffset);
|
|
5596
5615
|
}
|
|
5597
5616
|
}
|
|
@@ -5660,7 +5679,8 @@ class __sveltets_Render${genericsDef} {
|
|
|
5660
5679
|
}
|
|
5661
5680
|
else {
|
|
5662
5681
|
statement +=
|
|
5663
|
-
|
|
5682
|
+
'\n\nimport { SvelteComponentTyped as __SvelteComponentTyped__ } from "svelte" \n' +
|
|
5683
|
+
`${doc}export default class${className ? ` ${className}` : ''}${genericsDef} extends __SvelteComponentTyped__<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> {` +
|
|
5664
5684
|
exportedNames.createClassGetters() +
|
|
5665
5685
|
(usesAccessors ? exportedNames.createClassAccessors() : '') +
|
|
5666
5686
|
'\n}';
|
|
@@ -6129,13 +6149,14 @@ async function emitDts(config) {
|
|
|
6129
6149
|
const svelteMap = await createSvelteMap(config);
|
|
6130
6150
|
const { options, filenames } = loadTsconfig(config, svelteMap);
|
|
6131
6151
|
const host = await createTsCompilerHost(options, svelteMap);
|
|
6132
|
-
const program =
|
|
6152
|
+
const program = ts.createProgram(filenames, options, host);
|
|
6133
6153
|
program.emit();
|
|
6134
6154
|
}
|
|
6135
6155
|
function loadTsconfig(config, svelteMap) {
|
|
6156
|
+
var _a;
|
|
6136
6157
|
const libRoot = config.libRoot || process.cwd();
|
|
6137
|
-
const jsconfigFile =
|
|
6138
|
-
let tsconfigFile =
|
|
6158
|
+
const jsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists, 'jsconfig.json');
|
|
6159
|
+
let tsconfigFile = ts.findConfigFile(libRoot, ts.sys.fileExists);
|
|
6139
6160
|
if (!tsconfigFile && !jsconfigFile) {
|
|
6140
6161
|
throw new Error('Failed to locate tsconfig or jsconfig');
|
|
6141
6162
|
}
|
|
@@ -6145,7 +6166,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6145
6166
|
}
|
|
6146
6167
|
tsconfigFile = path.isAbsolute(tsconfigFile) ? tsconfigFile : path.join(libRoot, tsconfigFile);
|
|
6147
6168
|
const basepath = path.dirname(tsconfigFile);
|
|
6148
|
-
const { error, config: tsConfig } =
|
|
6169
|
+
const { error, config: tsConfig } = ts.readConfigFile(tsconfigFile, ts.sys.readFile);
|
|
6149
6170
|
if (error) {
|
|
6150
6171
|
throw new Error('Malformed tsconfig\n' + JSON.stringify(error, null, 2));
|
|
6151
6172
|
}
|
|
@@ -6157,7 +6178,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6157
6178
|
tsConfig.include = [`${libPathRelative}/**/*`];
|
|
6158
6179
|
tsConfig.files = [];
|
|
6159
6180
|
}
|
|
6160
|
-
const { options, fileNames } =
|
|
6181
|
+
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
6182
|
const filenames = fileNames.map((name) => {
|
|
6162
6183
|
if (!isSvelteFilepath(name)) {
|
|
6163
6184
|
return name;
|
|
@@ -6175,7 +6196,9 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6175
6196
|
options: {
|
|
6176
6197
|
...options,
|
|
6177
6198
|
noEmit: false,
|
|
6178
|
-
moduleResolution:
|
|
6199
|
+
moduleResolution:
|
|
6200
|
+
// NodeJS: up to 4.9, Node10: since 5.0
|
|
6201
|
+
(_a = ts.ModuleResolutionKind.NodeJs) !== null && _a !== void 0 ? _a : ts.ModuleResolutionKind.Node10,
|
|
6179
6202
|
declaration: true,
|
|
6180
6203
|
emitDeclarationOnly: true,
|
|
6181
6204
|
declarationDir: config.declarationDir,
|
|
@@ -6185,7 +6208,7 @@ function loadTsconfig(config, svelteMap) {
|
|
|
6185
6208
|
};
|
|
6186
6209
|
}
|
|
6187
6210
|
async function createTsCompilerHost(options, svelteMap) {
|
|
6188
|
-
const host =
|
|
6211
|
+
const host = ts.createCompilerHost(options);
|
|
6189
6212
|
// TypeScript writes the files relative to the found tsconfig/jsconfig
|
|
6190
6213
|
// which - at least in the case of the tests - is wrong. Therefore prefix
|
|
6191
6214
|
// the output paths. See Typescript issue #25430 for more.
|
|
@@ -6194,10 +6217,10 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6194
6217
|
.split(path.sep)
|
|
6195
6218
|
.join('/');
|
|
6196
6219
|
const svelteSys = {
|
|
6197
|
-
...
|
|
6220
|
+
...ts.sys,
|
|
6198
6221
|
fileExists(originalPath) {
|
|
6199
6222
|
const path = ensureRealSvelteFilepath(originalPath);
|
|
6200
|
-
const exists =
|
|
6223
|
+
const exists = ts.sys.fileExists(path);
|
|
6201
6224
|
if (exists && isSvelteFilepath(path)) {
|
|
6202
6225
|
const isTsFile = svelteMap.add(path);
|
|
6203
6226
|
if ((isTsFile && !isTsFilepath(originalPath)) ||
|
|
@@ -6213,12 +6236,12 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6213
6236
|
return svelteMap.get(path);
|
|
6214
6237
|
}
|
|
6215
6238
|
else {
|
|
6216
|
-
return
|
|
6239
|
+
return ts.sys.readFile(path, encoding);
|
|
6217
6240
|
}
|
|
6218
6241
|
},
|
|
6219
6242
|
readDirectory(path, extensions, exclude, include, depth) {
|
|
6220
6243
|
const extensionsWithSvelte = (extensions || []).concat('.svelte');
|
|
6221
|
-
return
|
|
6244
|
+
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
|
|
6222
6245
|
},
|
|
6223
6246
|
writeFile(fileName, data, writeByteOrderMark) {
|
|
6224
6247
|
fileName = pathPrefix ? path.join(pathPrefix, fileName) : fileName;
|
|
@@ -6248,7 +6271,7 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6248
6271
|
return `"sources":["${sourcePath}"]`;
|
|
6249
6272
|
});
|
|
6250
6273
|
}
|
|
6251
|
-
return
|
|
6274
|
+
return ts.sys.writeFile(fileName, data, writeByteOrderMark);
|
|
6252
6275
|
}
|
|
6253
6276
|
};
|
|
6254
6277
|
host.fileExists = svelteSys.fileExists;
|
|
@@ -6260,15 +6283,22 @@ async function createTsCompilerHost(options, svelteMap) {
|
|
|
6260
6283
|
return resolveModuleName(moduleName, containingFile, compilerOptions);
|
|
6261
6284
|
});
|
|
6262
6285
|
};
|
|
6286
|
+
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, _redirectedReference, compilerOptions) => {
|
|
6287
|
+
return moduleLiterals.map((moduleLiteral) => {
|
|
6288
|
+
return {
|
|
6289
|
+
resolvedModule: resolveModuleName(moduleLiteral.text, containingFile, compilerOptions)
|
|
6290
|
+
};
|
|
6291
|
+
});
|
|
6292
|
+
};
|
|
6263
6293
|
function resolveModuleName(name, containingFile, compilerOptions) {
|
|
6264
6294
|
// Delegate to the TS resolver first.
|
|
6265
6295
|
// If that does not bring up anything, try the Svelte Module loader
|
|
6266
6296
|
// which is able to deal with .svelte files.
|
|
6267
|
-
const tsResolvedModule =
|
|
6297
|
+
const tsResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, ts.sys).resolvedModule;
|
|
6268
6298
|
if (tsResolvedModule && !isVirtualSvelteFilepath(tsResolvedModule.resolvedFileName)) {
|
|
6269
6299
|
return tsResolvedModule;
|
|
6270
6300
|
}
|
|
6271
|
-
return
|
|
6301
|
+
return ts.resolveModuleName(name, containingFile, compilerOptions, svelteSys)
|
|
6272
6302
|
.resolvedModule;
|
|
6273
6303
|
}
|
|
6274
6304
|
return host;
|
|
@@ -6282,7 +6312,7 @@ async function createSvelteMap(config) {
|
|
|
6282
6312
|
const svelteFiles = new Map();
|
|
6283
6313
|
function add(path) {
|
|
6284
6314
|
var _a, _b;
|
|
6285
|
-
const code =
|
|
6315
|
+
const code = ts.sys.readFile(path, 'utf-8');
|
|
6286
6316
|
const isTsFile = // svelte-preprocess allows default languages
|
|
6287
6317
|
['ts', 'typescript'].includes((_b = (_a = config.preprocess) === null || _a === void 0 ? void 0 : _a.defaultLanguages) === null || _b === void 0 ? void 0 : _b.script) ||
|
|
6288
6318
|
/<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.11",
|
|
4
4
|
"description": "Convert Svelte components to TSX for type checking",
|
|
5
5
|
"author": "David Pershouse",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,14 +34,14 @@
|
|
|
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",
|
|
44
|
-
"typescript": "^4.9.4"
|
|
44
|
+
"typescript": "^4.9.4 || ^5.0.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "rollup -c",
|
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
|