Skip to content

Commit 34f2c13

Browse files
author
Andrew Schmadel
committed
cleanup; remove need to transpile main module
1 parent 950fe9e commit 34f2c13

6 files changed

Lines changed: 32 additions & 25 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,23 @@ far from Esprima to make that goal realistic. (I would love to be proven wrong
2121

2222
That being said, this is my short-term todo list:
2323

24-
* Support the majority of invocations/annotations currently performed by ng-annotate
25-
* Split up ng-annotate's test suite to be more granular and tolerant of some of babel's other transforms.
26-
* Actually pass those tests.
24+
✓ Support the majority of invocations/annotations currently performed by ng-annotate
25+
✓ Split up ng-annotate's test suite to be more granular and tolerant of some of babel's other transforms.
26+
✓ Actually pass those tests.
27+
* Pass tests in conjunction with the ES2015 preset.
2728
* Cleanup. Remove vestigial functionality from the upstream project.
2829
* Support a (very) limited set of ES6-friendly annotation patterns.
2930
* Publish to npm, make a release, etc.
3031

3132

3233
## Don't Say I Didn't Warn You
3334

34-
To test this mess of an experiment, compile the ES6 sources into something that Node can run:
35-
36-
```
37-
babel babel-ng-annotate.js -o babel-ng-annotate-harmony.js
38-
```
39-
40-
Create a .babelrc file for your sources
35+
To test this mess of an experiment, create a .babelrc file for your sources
4136

4237
```json
4338
{
4439
"presets": ["es2015"],
45-
"plugins": ["path/to/babel-ng-annotate-harmony"]
40+
"plugins": ["path/to/babel-ng-annotate"]
4641
}
4742

4843
```
@@ -53,6 +48,11 @@ And try it out:
5348
babel original.js
5449
```
5550

51+
### To run tests:
52+
53+
```
54+
node tests/tests.js
55+
```
5656

5757

5858
## License

babel-ng-annotate.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { match, addModuleContextDependentSuspect, addModuleContextIndependentSuspect,
2-
judgeSuspects, matchDirectiveReturnObject,
3-
matchProviderGet } from './ng-annotate-main.js'
1+
'use strict';
42

5-
import ngInject from './nginject';
6-
import is from 'simple-is';
3+
var ngAnnotate = require('./ng-annotate-main');
4+
const ngInject = require('./nginject');
5+
const is = require('simple-is');
76

8-
export default function({ types: t }) {
7+
const match = ngAnnotate.match;
8+
const addModuleContextDependentSuspect = ngAnnotate.addModuleContextDependentSuspect;
9+
const addModuleContextIndependentSuspect = ngAnnotate.addModuleContextIndependentSuspect;
10+
const judgeSuspects = ngAnnotate.judgeSuspects;
11+
const matchDirectiveReturnObject = ngAnnotate.matchDirectiveReturnObject;
12+
const matchProviderGet = ngAnnotate.matchProviderGet;
13+
14+
15+
module.exports = function() {
916

1017
var options = {};
1118

@@ -104,7 +111,7 @@ export default function({ types: t }) {
104111
return file.file.code.slice(node.start, node.end);
105112
};
106113
},
107-
exit(path) {
114+
exit() {
108115
judgeSuspects(ctx);
109116
}
110117
}

ng-annotate-main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function insertArray(ctx, path) {
475475

476476
}
477477

478+
// TODO: Is this necessary?
478479
function renameProviderDeclarationSite(ctx, literalNode, fragments) {
479480
fragments.push({
480481
start: literalNode.range[0] + 1,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"devDependencies": {
2626
"babel": "^6.5.1",
2727
"babel-core": "^6.5.1",
28-
"babel-preset-es2015": "^6.3.13",
28+
"babel-preset-es2015": "^6.5.0",
2929
"chalk": "^1.1.1",
3030
"coffee-script": "~1.10.0",
3131
"defs": "~1.1.1",

tests/.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"presets": ["es2015"],
3-
"plugins": ["../babel-ng-annotate-harmony"]
2+
"plugins": ["../babel-ng-annotate"]
43
}

tests/tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function runTests(tests){
4040
}
4141

4242
function runTest(test) {
43-
var out = babel.transform(fnBody(test.input), { plugins: "../babel-ng-annotate-harmony" });
44-
var expected = babel.transform(fnBody(test.expected));
43+
var out = babel.transform(fnBody(test.input), { plugins: "../babel-ng-annotate", presets: ["../es2015-modified"] });
44+
var expected = babel.transform(fnBody(test.expected), { plugins: [], presets: ["../es2015-modified"] });
4545

4646
if(out.code.trim() != expected.code.trim()){
4747
console.warn(" " + test.name + ": " + chalk.red.bold("FAILED."));
@@ -83,8 +83,8 @@ function printDiff(expected, actual){
8383
}).reduce((memo, val) => memo + val, "");
8484
console.warn(msg);
8585

86-
console.warn(chalk.bold("GOT:") + "\n" + actual);
87-
console.warn(chalk.bold("WANTED:") + "\n" + expected + '\n');
86+
// console.warn(chalk.bold("GOT:") + "\n" + actual);
87+
// console.warn(chalk.bold("WANTED:") + "\n" + expected + '\n');
8888
}
8989

9090
suites.forEach(runSuite);

0 commit comments

Comments
 (0)