Skip to content

Report error if class uses extended type before its declaration #4343

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

Closed
wants to merge 20 commits into from

Conversation

sheetalkamat
Copy link
Member

Fixes #4341

@@ -0,0 +1,15 @@
var c = class A extends B { // error
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i would also add a test with an expression in an extend clause, class A extends foo(0)<string> {}
and one for module aliases

import d from "mod"; 
class B extends d { // no error here
}

Copy link
Member Author

Choose a reason for hiding this comment

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

added this

@sheetalkamat
Copy link
Member Author

I am still working on reporting error if alias is declared before it is referencing entity(internal alias only)
Update: its done now.

let file1 = getSourceFileOfNode(node1);
let file2 = getSourceFileOfNode(node2);
if (file1 === file2) {
return node1.pos <= node2.pos;
return node1.pos <= node2.pos || !isInSameLexicalScope();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are they allowed to be in different lexical scopes?

@@ -393,9 +398,28 @@ namespace ts {
}

let sourceFiles = host.getSourceFiles();
return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2);
}
return sourceFiles.indexOf(referenceDeclarationFile) <= sourceFiles.indexOf(locationNodeFile) || !isInSameLexicalScope();
Copy link
Contributor

Choose a reason for hiding this comment

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

use ts.indexOf instead of array.prototype.indexof

return;
}

let meaning = node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccessExpression?
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix spacing at the end of the line

let file2 = getSourceFileOfNode(node2);
if (file1 === file2) {
return node1.pos <= node2.pos;
function isDefinedBefore(referenceDeclaration: Node, locationNode: Node): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

isDefinedBeforeOrAt

@weswigham
Copy link
Member

This PR is superseded by #8636 which has been successfully merged, right?

@mhegazy
Copy link
Contributor

mhegazy commented Sep 13, 2016

closing in favor of #8636

@mhegazy mhegazy closed this Sep 13, 2016
@mhegazy mhegazy deleted the baseClassDeclarationOrder branch September 13, 2016 22:11
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants