Skip to content

JS Flow Annotation Support and A Proper Plugin System #470

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 11 commits into from
Jun 20, 2016
Merged

Conversation

amadeus
Copy link
Collaborator

@amadeus amadeus commented Jun 12, 2016

I have begun work on JS Flow annotation support. This is a PR/Branch where it's currently on by default, however when this eventually gets merged, it should be hidden behind a global boolean, and perhaps even sourced from another file completely so as not to clutter up the main syntax file.

This is the test file I am using for it:

function bar(x: string, y: number): string {
  return x.length * y;
}

function total(numbers: Array<number>) {
  var result = 0;
  for (var i = 0; i < numbers.length; i++) {
    result += numbers[i];
  }
  return result;
}

function foo(a: string, b: number): { key: number,  bool: boolean } {}

function foo(a: string, b: number): [ string, number ] {
}

function foo(a: string, b: number):object {}

function foo(a: string, b: number):object {
}

function foo(x: string): string { return x; }

function foo(a: string, b: number):void { }

var x: boolean = someBool;

class Bar {
  y: string;
  someMethod(a: number): string {
  }
}

let array: number[] = [1, 2, 3.14, 42];

let theAnswer: number = array[3]; // 42

let offTheEnd: number = array[100]; // No error

let array2: Array<string> = ["an alternate", "syntax", "for arrays"];

let tuple: [string, number, boolean] = ["foo", 0, true];

// Indexing into the array will return the type at a given index.
(tuple[0]: string);
(tuple[1]: string);

// Indexing into an statically unknown index will return a general type.
declare var unknownNumber: number;

// `void` is none of `string`, `number`, or `boolean`
(tuple[unknownNumber]: void);
(tuple[unknownNumber]: string|number|boolean); // OK

// Values written must be compatible with the type at that index.
tuple[1] = -1;
tuple[0] = false;

let object: {foo: string, bar: number} = {foo: "foo", bar: 0};
(object.foo: string);

function exampleMethod(someString: string, someRecord: Record): {resultString: string, resultString2: string} {}

I could probably use more test examples. Any of you who use JS Flow should please check out this branch and help test it!

Here's a screenshot of what JS Flow support currently looks like:

JS Flow Example

@amadeus amadeus self-assigned this Jun 12, 2016
@amadeus amadeus force-pushed the js-flow-support branch 4 times, most recently from d532374 to 9dae81b Compare June 18, 2016 04:09
@amadeus amadeus changed the title JS Flow Annotation Support - Not Ready To Merge JS Flow Annotation Support Jun 18, 2016
@amadeus amadeus changed the title JS Flow Annotation Support JS Flow Annotation Support and A Proper Plugin System Jun 18, 2016
@amadeus amadeus mentioned this pull request Jun 18, 2016
@amadeus
Copy link
Collaborator Author

amadeus commented Jun 18, 2016

I've finally gotten around to adding a proper way for us to have plugins.

This particular PR adds plugins for Flow, NGDocs and JSDocs. I could probably still refine how this all works, for example there's a dependency issue where NGDocs is dependent on JSDocs, so I'll still need to come up with a system to standardize those dependencies.

amadeus added 9 commits June 19, 2016 22:40
This is by no means complete, and so far has only been to fix major
syntax highlighting issues I've found.
Also linked jsFlowNoise to Noise
syntax include has a sort of sugar to it that forces all sourced
highlighting to be contained, this will break certain more general
highlighting for jsFlow.

runtime on the other hand, works exactly as you'd expect.
amadeus added 2 commits June 19, 2016 22:48
* JSDocs are now hidden behind a variable for consistency with other
  plugins
* NGDoc plugin can now only be enabled if JSDoc is enabled.
* Added README documentation for the new global booleans
@amadeus amadeus merged commit 8deb698 into develop Jun 20, 2016
@amadeus amadeus deleted the js-flow-support branch June 20, 2016 05:51
@bounceme
Copy link
Collaborator

bounceme commented Jun 20, 2016

how about setting the jsdoc variable in the ngdoc file?then users won't need to explicitly define it

basically : see if variable is set; if it isn't then source the jsdoc file

@amadeus
Copy link
Collaborator Author

amadeus commented Jun 20, 2016

Not sure I follow? NGDocs just add a few things to the existing JSDoc syntax. I don't think they should necessarily be on for JSDocs since they are very angular specific? Furthermore, if there are additional things people would like to add to NGDocs, then they could be added to that respective file.

@bounceme
Copy link
Collaborator

What I was thinking is basically just adding a vimscript require('jsdoc') at the top of the ngdoc file. i guess most people who want ngdoc will also already be using the normal jsdoc variable though

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