mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Handle parentless nodes in isParameterPropertyDeclaration
Fixes #33295. This follows a similar pattern as in #20314 by requiring an explicit `parent` parameter. Where possible, it uses the appopriate variable at the call sites. In several locations there is no context available though (e.g. inspecting `valueDeclarations`) and we access `.parent` as the code previously did. From a cursory inspection this seems correct, these callpaths originate in phases where there must be a `parent` (i.e. in checker, binder, etc). Change-Id: I28e4726777b57237bec776e4001e9e69ac591b11
This commit is contained in:
committed by
Daniel Rosenwasser
parent
2f8832cccc
commit
6bb7e5c086
@@ -300,6 +300,34 @@ namespace ts {
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/33295
|
||||
testBaseline("transformParameterProperty", () => {
|
||||
return transpileModule("", {
|
||||
transformers: {
|
||||
before: [transformAddParameterProperty],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ScriptTarget.ES5,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
|
||||
function transformAddParameterProperty(_context: TransformationContext) {
|
||||
return (sourceFile: SourceFile): SourceFile => {
|
||||
return visitNode(sourceFile);
|
||||
};
|
||||
function visitNode(sf: SourceFile) {
|
||||
// produce `class Foo { constructor(@Dec private x) {} }`;
|
||||
// The decorator is required to trigger ts.ts transformations.
|
||||
const classDecl = createClassDeclaration([], [], "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, [
|
||||
createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, [
|
||||
createParameter(/*decorators*/ [createDecorator(createIdentifier("Dec"))], /*modifiers*/ [createModifier(SyntaxKind.PrivateKeyword)], /*dotDotDotToken*/ undefined, "x")], createBlock([]))
|
||||
]);
|
||||
return updateSourceFileNode(sf, [classDecl]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function baselineDeclarationTransform(text: string, opts: TranspileOptions) {
|
||||
const fs = vfs.createFromFileSystem(Harness.IO, /*caseSensitive*/ true, { documents: [new documents.TextDocument("/.src/index.ts", text)] });
|
||||
const host = new fakes.CompilerHost(fs, opts.compilerOptions);
|
||||
@@ -389,7 +417,7 @@ class Clazz {
|
||||
}
|
||||
`, {
|
||||
transformers: {
|
||||
before: [addSyntheticComment(n => isPropertyDeclaration(n) || isParameterPropertyDeclaration(n) || isClassDeclaration(n) || isConstructorDeclaration(n))],
|
||||
before: [addSyntheticComment(n => isPropertyDeclaration(n) || isParameterPropertyDeclaration(n, n.parent) || isClassDeclaration(n) || isConstructorDeclaration(n))],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ScriptTarget.ES2015,
|
||||
|
||||
Reference in New Issue
Block a user