-
-
Notifications
You must be signed in to change notification settings - Fork 184
Implemented support for properties on functions #1180
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import * as util from "../../util"; | ||
|
|
||
| test("property on function", () => { | ||
| util.testFunction` | ||
| function foo(s: string) { return s; } | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("property on void function", () => { | ||
| util.testFunction` | ||
| function foo(this: void, s: string) { return s; } | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("property on recursively referenced function", () => { | ||
| util.testFunction` | ||
| function foo(s: string) { return s + foo.bar; } | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("property on hoisted function", () => { | ||
| util.testFunction` | ||
| foo.bar = "bar"; | ||
| function foo(s: string) { return s; } | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("function merged with namespace", () => { | ||
| util.testModule` | ||
| function foo(s: string) { return s; } | ||
| namespace foo { | ||
| export let bar = "bar"; | ||
| } | ||
| export const result = foo("foo") + foo.bar; | ||
| ` | ||
| .setReturnExport("result") | ||
| .expectToEqual("foobar"); | ||
| }); | ||
|
|
||
| test("function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo = function(s: string) { return s; }; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("void function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo = function(this: void, s: string) { return s; }; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("recursively referenced function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo = function(s: string) { return s + foo.bar; }; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("named recursively referenced function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo = function baz(s: string) { return s + foo.bar + baz.bar; }; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("arrow function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo: { (s: string): string; bar: string; } = s => s; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("void arrow function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo: { (this: void, s: string): string; bar: string; } = s => s; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("recursively referenced arrow function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo: { (s: string): string; bar: string; } = s => s + foo.bar; | ||
| foo.bar = "bar"; | ||
| return foo("foo") + foo.bar; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("property on generator function", () => { | ||
| util.testFunction` | ||
| function *foo(s: string) { yield s; } | ||
| foo.bar = "bar"; | ||
| for (const s of foo("foo")) { | ||
| return s + foo.bar; | ||
| } | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("generator function assigned to variable", () => { | ||
| util.testFunction` | ||
| const foo = function *(s: string) { yield s; } | ||
| foo.bar = "bar"; | ||
| for (const s of foo("foo")) { | ||
| return s + foo.bar; | ||
| } | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("property on async function", () => { | ||
| util.testFunction` | ||
| let result = ""; | ||
| async function foo(s: string) { result = s + foo.bar; } | ||
| foo.bar = "bar"; | ||
| void foo("foo"); | ||
| return result; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("async function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| let result = ""; | ||
| const foo = async function(s: string) { result = s + foo.bar; } | ||
| foo.bar = "bar"; | ||
| void foo("foo"); | ||
| return result; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("async arrow function with property assigned to variable", () => { | ||
| util.testFunction` | ||
| let result = ""; | ||
| const foo: { (s: string): Promise<void>; bar: string; } = async s => { result = s + foo.bar; }; | ||
| foo.bar = "bar"; | ||
| void foo("foo"); | ||
| return result; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("call function with property using call method", () => { | ||
| util.testFunction` | ||
| function foo(s: string) { return this + s; } | ||
| foo.baz = "baz"; | ||
| return foo.call("foo", "bar") + foo.baz; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("call function with property using apply method", () => { | ||
| util.testFunction` | ||
| function foo(s: string) { return this + s; } | ||
| foo.baz = "baz"; | ||
| return foo.apply("foo", ["bar"]) + foo.baz; | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
||
| test("call function with property using bind method", () => { | ||
| util.testFunction` | ||
| function foo(s: string) { return this + s; } | ||
| foo.baz = "baz"; | ||
| return foo.bind("foo", "bar")() + foo.baz; | ||
| `.expectToMatchJsResult(); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a mistake, this should be default to catch everything we have not handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since functions can have any properties, we don't want to throw errors on them being used. So I changed this to only error on JS lib functions that we don't handle.