Skip to content

Commit ea5effe

Browse files
committed
Migration: js() to addJS() tests added
1 parent f869eff commit ea5effe

8 files changed

+60
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var log = require('../logger');
2+
var Transformer = require('../transformer');
3+
var t = new Transformer();
4+
5+
module.exports = function(file, api, opts) {
6+
t.description = 'You can’t use more than one subpredicate block, elem, mod, elemMod. ' +
7+
'And more than one output generator like tag(), content(), etc ';
8+
9+
t.find = function(file, j) {
10+
return j(file.source)
11+
.find(j.MemberExpression, {
12+
property: { type: 'Identifier', name: 'block' },
13+
object: { callee: { type: 'Identifier', name: 'block' }}
14+
})
15+
};
16+
17+
t.replace = function(ret, j) {
18+
return ret.replaceWith(function(p) {
19+
return j.identifier('block');
20+
});
21+
};
22+
23+
return t.run(file, api, opts);
24+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
block('a').block('b').tag()('a');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
block('b').tag()('a');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
block('test').js()(function() {
2+
// TODO: ololo
3+
var js = this.ctx.js;
4+
5+
js = { data: 'lol' };
6+
7+
return js;
8+
});
9+
10+
block('test').js()(true);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
block('test').addJs()(function() {
2+
// TODO: ololo
3+
var js = this.ctx.js;
4+
5+
js = { data: 'lol' };
6+
7+
return js;
8+
});
9+
10+
block('test').addJs()(true);

migration/lib/transformers/__testfixtures__/8-js-to-addjs-1.input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ block('b')(
55

66
content()('test')
77
);
8+
9+
block('b')(
10+
js()(true),
11+
12+
content()('test')
13+
);

migration/lib/transformers/__testfixtures__/8-js-to-addjs-1.output.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ block('b')(
55

66
content()('test')
77
);
8+
9+
block('b')(
10+
addJs()(true),
11+
12+
content()('test')
13+
);

migration/lib/transformers/__tests__/common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ defineTest(__dirname, '8-mix-to-addmix', null, '8-mix-to-addmix-1');
4242
defineTest(__dirname, '8-mix-to-addmix', null, '8-mix-to-addmix-2');
4343
defineTest(__dirname, '8-js-to-addjs', null, '8-js-to-addjs-1');
4444
defineTest(__dirname, '8-js-to-addjs', null, '8-js-to-addjs-2');
45+
defineTest(__dirname, '8-chain-js-to-chain-addjs', null, '8-chain-js-to-chain-addjs-1');
46+
defineTest(__dirname, '8-block-in-block', null, '8-block-in-block-chain-1');

0 commit comments

Comments
 (0)