Skip to content

Commit 0b91219

Browse files
committed
Added mangling loader for ts files in extensions
1 parent 4a040f6 commit 0b91219

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

extensions/mangle-loader.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
// @ts-check
6+
7+
const webpack = require('webpack');
8+
const { Mangler } = require('../build/lib/mangleTypeScript');
9+
10+
let map;
11+
/**
12+
* @param {string} projectPath
13+
*/
14+
function getMangledFileContents(projectPath) {
15+
if (!map) {
16+
const ts2tsMangler = new Mangler(projectPath, console.log);
17+
map = ts2tsMangler.computeNewFileContents();
18+
}
19+
20+
return map;
21+
}
22+
23+
/**
24+
* @type {webpack.LoaderDefinitionFunction}
25+
*/
26+
module.exports = async function (source, sourceMap, meta) {
27+
const options = this.getOptions();
28+
const callback = this.async();
29+
30+
const fileContentsMap = getMangledFileContents(options.configFile);
31+
32+
const newContents = fileContentsMap.get(this.resourcePath);
33+
callback(null, newContents ?? source, sourceMap, meta);
34+
};

extensions/markdown-language-features/src/test/engine.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ import * as vscode from 'vscode';
77
import { MarkdownItEngine } from '../markdownEngine';
88
import { MarkdownContributionProvider, MarkdownContributions } from '../markdownExtensions';
99
import { githubSlugifier } from '../slugify';
10-
import { Disposable } from '../util/dispose';
1110
import { nulLogger } from './nulLogging';
1211

13-
const emptyContributions = new class extends Disposable implements MarkdownContributionProvider {
12+
const emptyContributions = new class implements MarkdownContributionProvider {
1413
readonly extensionUri = vscode.Uri.file('/');
1514
readonly contributions = MarkdownContributions.Empty;
16-
readonly onContributionsChanged = this._register(new vscode.EventEmitter<this>()).event;
15+
16+
private readonly _onContributionsChanged = new vscode.EventEmitter<this>();
17+
readonly onContributionsChanged = this._onContributionsChanged.event;
18+
19+
dispose() {
20+
this._onContributionsChanged.dispose();
21+
}
1722
};
1823

1924
export function createNewMarkdownEngine(): MarkdownItEngine {

extensions/shared.webpack.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ function withNodeDefaults(/**@type WebpackConfig*/extConfig) {
4747
'sourceMap': true,
4848
}
4949
}
50-
}]
50+
}, {
51+
loader: path.resolve(__dirname, './mangle-loader.js'),
52+
options: {
53+
configFile: path.join(extConfig.context, 'tsconfig.json')
54+
},
55+
},]
5156
}]
5257
},
5358
externals: {
@@ -125,7 +130,14 @@ function withBrowserDefaults(/**@type WebpackConfig*/extConfig, /** @type Additi
125130
},
126131
...(additionalOptions ? {} : { configFile: additionalOptions.configFile })
127132
}
128-
}]
133+
},
134+
{
135+
loader: path.resolve(__dirname, './mangle-loader.js'),
136+
options: {
137+
configFile: path.join(extConfig.context, additionalOptions?.configFile ?? 'tsconfig.json')
138+
},
139+
},
140+
]
129141
}]
130142
},
131143
externals: {

0 commit comments

Comments
 (0)