Skip to content

Commit fa002cb

Browse files
Fix api, tree.messages and tree.options
1 parent e334dab commit fa002cb

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/extend.es6

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import util from 'util';
44
import parseToPostHtml from 'posthtml-parser';
5-
import * as api from 'posthtml/lib/api';
6-
5+
import Api from 'posthtml/lib/api';
76

87
const errors = {
98
'EXTENDS_NO_SRC': '<extends> has no "src"',
@@ -32,8 +31,17 @@ export default (options = {}) => {
3231
};
3332
};
3433

34+
const api = new Api;
35+
let baseFileOpts;
3536

3637
function handleExtendsNodes(tree, options) {
38+
baseFileOpts = baseFileOpts || tree.options;
39+
tree.options = tree.options || baseFileOpts;
40+
41+
if (!tree.messages) {
42+
tree.messages = [];
43+
}
44+
3745
api.match.call(applyPluginsToTree(tree, options.plugins), {tag: 'extends'}, extendsNode => {
3846
if (! extendsNode.attrs || ! extendsNode.attrs.src) {
3947
throw getError(errors.EXTENDS_NO_SRC);
@@ -43,14 +51,6 @@ function handleExtendsNodes(tree, options) {
4351
const layoutHtml = fs.readFileSync(layoutPath, options.encoding);
4452
let layoutTree;
4553

46-
if (!tree.messages) {
47-
apiExtend(tree);
48-
}
49-
50-
if (!tree.options) {
51-
tree.options = {};
52-
}
53-
5454
tree.messages.push({
5555
type: 'dependency',
5656
file: layoutPath,
@@ -151,10 +151,4 @@ function getBlockNodes(content = []) {
151151
function getError() {
152152
const message = util.format.apply(util, arguments);
153153
return new Error('[posthtml-extend] ' + message);
154-
}
155-
156-
function apiExtend(tree) {
157-
tree.walk = api.walk;
158-
tree.match = api.match;
159-
tree.messages = api.messages;
160154
}

0 commit comments

Comments
 (0)