@@ -2,8 +2,7 @@ import fs from 'fs';
2
2
import path from 'path' ;
3
3
import util from 'util' ;
4
4
import parseToPostHtml from 'posthtml-parser' ;
5
- import * as api from 'posthtml/lib/api' ;
6
-
5
+ import Api from 'posthtml/lib/api' ;
7
6
8
7
const errors = {
9
8
'EXTENDS_NO_SRC' : '<extends> has no "src"' ,
@@ -32,8 +31,17 @@ export default (options = {}) => {
32
31
} ;
33
32
} ;
34
33
34
+ const api = new Api ;
35
+ let baseFileOpts ;
35
36
36
37
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
+
37
45
api . match . call ( applyPluginsToTree ( tree , options . plugins ) , { tag : 'extends' } , extendsNode => {
38
46
if ( ! extendsNode . attrs || ! extendsNode . attrs . src ) {
39
47
throw getError ( errors . EXTENDS_NO_SRC ) ;
@@ -43,14 +51,6 @@ function handleExtendsNodes(tree, options) {
43
51
const layoutHtml = fs . readFileSync ( layoutPath , options . encoding ) ;
44
52
let layoutTree ;
45
53
46
- if ( ! tree . messages ) {
47
- apiExtend ( tree ) ;
48
- }
49
-
50
- if ( ! tree . options ) {
51
- tree . options = { } ;
52
- }
53
-
54
54
tree . messages . push ( {
55
55
type : 'dependency' ,
56
56
file : layoutPath ,
@@ -151,10 +151,4 @@ function getBlockNodes(content = []) {
151
151
function getError ( ) {
152
152
const message = util . format . apply ( util , arguments ) ;
153
153
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 ;
160
154
}
0 commit comments