Skip to content

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

Merged
johnsoncodehk merged 5 commits intomasterfrom
multi-source-mapping
Jun 5, 2024
Merged

feat(language-core): reimplement multi-source mapping#194
johnsoncodehk merged 5 commits intomasterfrom
multi-source-mapping

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
@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