Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(language-core): reimplement multi-source mapping #194

Merged
merged 5 commits into from
Jun 5, 2024

Conversation

johnsoncodehk
Copy link
Member

@johnsoncodehk johnsoncodehk commented Jun 4, 2024

c4b297b removed multi-source support, but to support Angular use cases, this PR re-implements it.

Changes

  • getAssociatedScript needs to be called to explicitly register dependencies on additional sources.
  • Mappings with additional source scripts should be added to associatedScriptMappings instead of using the Mapping#source field.
  • The Mapping#source field has beed removed.

Example:

export const angularLanguagePlugin: LanguagePlugin<string> = {
	createVirtualCode(fileName, languageId, snapshot, { getAssociatedScript }) {
		if (fileName.endsWith('app.component.ts')) {

			// Register dependencies
			const templateScript = getAssociatedScript('.../template.html');

			if (templateScript) {
				return {
					mappings: [
						// Mappings for app.component.ts
					],
					associatedScriptMappings: new Map([
						[templateScript.id, [
							// Mappings for template.html
						]],
					])
				}
			}
		}
	},
};

}

export interface CodegenContext<T> {
getAssociatedScript(scriptId: T): SourceScript<T> | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact I'm not sure if "associated" is a better term than "related".

@piotrtomiak
Copy link
Contributor

@johnsoncodehk - thanks for taking a look at this so quickly! I am now trying to rebase my changes on top of these changes.

@johnsoncodehk johnsoncodehk merged commit 76f0d1b into master Jun 5, 2024
6 checks passed
@johnsoncodehk johnsoncodehk deleted the multi-source-mapping branch June 5, 2024 00:34
@piotrtomiak
Copy link
Contributor

@johnsoncodehk - I've finally managed to rebase the changes. It took more, because I as off most of yesterday. The PR is here: #197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants