-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support import paths with .gts extensions
Fixes #618
- Loading branch information
Showing
16 changed files
with
581 additions
and
302 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/core/src/transform/template/import-declaration-span.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as ts from 'typescript'; | ||
import { TSLib } from '../util.js'; | ||
import { CorrelatedSpansResult, PartialCorrelatedSpan } from './inlining/index.js'; | ||
import { Directive, SourceFile, TransformError } from './transformed-module.js'; | ||
import { GlintEmitMetadata } from '@glint/core/config-types'; | ||
import MappingTree, { GtsImport } from './mapping-tree.js'; | ||
|
||
export function calculateImportSpan( | ||
ts: TSLib, | ||
node: ts.ImportDeclaration, | ||
meta: GlintEmitMetadata | undefined, | ||
script: SourceFile | ||
): CorrelatedSpansResult { | ||
let directives: Array<Directive> = []; | ||
let errors: Array<TransformError> = []; | ||
let partialSpans: Array<PartialCorrelatedSpan> = []; | ||
let moduleSpecifierText = (node.moduleSpecifier as ts.StringLiteral).text; | ||
if (meta?.replaceExtension) { | ||
let newModuleSpecifier = ts.factory.createStringLiteral( | ||
moduleSpecifierText.replace(/\.gts$/, '.' + meta.replaceExtension) | ||
); | ||
let updatedNode = ts.factory.updateImportDeclaration( | ||
node, | ||
node.modifiers, | ||
node.importClause, | ||
newModuleSpecifier, | ||
node.assertClause | ||
); | ||
let originalStart = node.getStart(); | ||
let originalLength = node.getEnd() - originalStart; | ||
const printer = ts.createPrinter(); | ||
let transformedSource = printer.printNode( | ||
ts.EmitHint.Unspecified, | ||
updatedNode, | ||
node.getSourceFile() | ||
); | ||
partialSpans.push({ | ||
originalFile: script, | ||
originalStart, | ||
originalLength, | ||
insertionPoint: originalStart, | ||
transformedSource, | ||
mapping: new MappingTree( | ||
{ start: 0, end: transformedSource.length }, | ||
{ start: 0, end: originalLength }, | ||
[], | ||
new GtsImport() | ||
), | ||
}); | ||
} | ||
|
||
return { errors, directives, partialSpans }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ges/ts-template-imports-app/src/index.gts → ...orts-app/app/components/WorldGreeting.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
function repeat(params: [string, number] /*, hash*/): string { | ||
return params[0].repeat(params[1]); | ||
} | ||
|
||
const repeatHelper = helper(repeat); | ||
|
||
export default repeatHelper; |
3 changes: 3 additions & 0 deletions
3
test-packages/ts-template-imports-app/app/templates/application.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="main"> | ||
<Greeting @target="Earthling" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.