binhend 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/code.js +18 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/code.js CHANGED
@@ -17,7 +17,7 @@ function getCodeOfDependencies(component, rootPath, metadata) {
17
17
  var htmlTagDeclaration = getHtmlTagDeclaration(dependency);
18
18
 
19
19
  if (dependencyDelaration) {
20
- componentCode = componentCode.replace('{', `{\r\n${dependencyDelaration}\r\n`);
20
+ componentCode = injectFunctionCodeContent(componentCode, dependencyDelaration);
21
21
  }
22
22
 
23
23
  var blockCodes = [];
@@ -42,9 +42,13 @@ function getCodeOfDependencies(component, rootPath, metadata) {
42
42
  return codes.join('\r\n');
43
43
  }
44
44
 
45
+ function injectFunctionCodeContent(functionCodeString, injectionCode) {
46
+ return functionCodeString.replace(/(\(.*\)\s*{|\(.*\)\s*=>\s*{)/, `$1\r\n${injectionCode}`);
47
+ }
48
+
45
49
  function getDependencyDelaration(component, rootPath) {
46
50
  var dependencies = getMetadataOfDependencies(component, rootPath);
47
- var codes = [], fullCode = '';
51
+ var codes = [];
48
52
 
49
53
  for (var filePath in dependencies) {
50
54
  var { name, url, type } = dependencies[filePath];
@@ -55,15 +59,16 @@ function getDependencyDelaration(component, rootPath) {
55
59
 
56
60
  var declarationCode = codes.join(',');
57
61
 
62
+ codes = [];
63
+ codes.push(`var Binh = _Binh;`);
64
+
58
65
  if (declarationCode) {
59
- fullCode = [
60
- `var Binh = _Binh;`,
61
- `var${declarationCode};`,
62
- ''
63
- ].join('\r\n');
66
+ codes.push(`var${declarationCode};`);
64
67
  }
65
68
 
66
- return fullCode;
69
+ codes.push('');
70
+
71
+ return codes.join('\r\n');
67
72
  }
68
73
 
69
74
  function getMetadataOfDependencies(component, rootPath) {
@@ -144,13 +149,16 @@ function bundle(component, rootPath) {
144
149
  var componentCode = component.toString();
145
150
 
146
151
  if (dependencyDelaration) {
147
- componentCode = componentCode.replace('{', `{\r\n${dependencyDelaration}`);
152
+ componentCode = injectFunctionCodeContent(componentCode, dependencyDelaration);
148
153
  }
149
154
 
150
155
  var codes = [];
151
156
 
152
157
  if (codeOfDependencies) codes.push(codeOfDependencies);
153
- if (componentCode) codes.push(`Binh.${component.type}(${componentCode})${optionCode};`);
158
+ if (componentCode) {
159
+ codes.push(`Binh.${component.type}(${component.type})${optionCode};`);
160
+ codes.push(`${componentCode}`);
161
+ }
154
162
 
155
163
  return codes.join('\r\n');
156
164
  }