express-engine-jsx
Advanced tools
Comparing version 3.6.1 to 3.7.0
@@ -6,3 +6,3 @@ const babel = require('@babel/core'); | ||
const t = require('@babel/types'); | ||
const fs = require('fs'); | ||
const {readFileSync} = require('fs'); | ||
const attrMap = require('./attr-map'); | ||
@@ -13,3 +13,3 @@ const options = require('./options'); | ||
convert.cache = {}; | ||
convert.cache = new Map(); | ||
@@ -26,3 +26,3 @@ function convert(code, params = {}) { | ||
var result = babel.transformSync(code, { | ||
const result = babel.transformSync(code, { | ||
filename: path, | ||
@@ -49,2 +49,3 @@ sourceMap, | ||
// noinspection JSUnusedGlobalSymbols | ||
return { | ||
@@ -77,3 +78,3 @@ visitor: { | ||
if (templatePath && !template) { | ||
template = cache[templatePath] || fs.readFileSync(templatePath); | ||
template = cache.has(templatePath) ? cache.get(templatePath) : readFileSync(templatePath); | ||
} | ||
@@ -92,3 +93,3 @@ | ||
if (templatePath) { | ||
cache[templatePath] = template; | ||
cache.set(templatePath, template); | ||
} | ||
@@ -101,7 +102,7 @@ } | ||
var IMPORTS = []; | ||
var BODY = []; | ||
const IMPORTS = []; | ||
const BODY = []; | ||
path.get('body').forEach(function (item) { | ||
var {node} = item; | ||
const {node} = item; | ||
@@ -127,4 +128,4 @@ if (isExport(node)) { | ||
JSXAttribute: function (path) { | ||
var name = path.node.name.name; | ||
var parent = path.parent; | ||
let name = path.node.name.name; | ||
const parent = path.parent; | ||
@@ -161,2 +162,3 @@ if ( | ||
// noinspection JSUnusedGlobalSymbols | ||
return { | ||
@@ -166,5 +168,5 @@ visitor: { | ||
exit: function (path) { | ||
var {body} = path.node; | ||
const {body} = path.node; | ||
var node = body.find(node => ( | ||
const node = body.find(node => ( | ||
t.isVariableDeclaration(node) && | ||
@@ -180,3 +182,3 @@ (node = node.declarations[0]) && | ||
var index = body.indexOf(node); | ||
const index = body.indexOf(node); | ||
@@ -190,4 +192,4 @@ if (index === 0) return; | ||
CallExpression: function ({node}) { | ||
var {callee, arguments: args} = node; | ||
var first = args[0]; | ||
const {callee, arguments: args} = node; | ||
const first = args[0]; | ||
@@ -194,0 +196,0 @@ if ( |
@@ -33,5 +33,11 @@ import {Stream} from "node:stream"; | ||
export function require(path: string, currentWorkingDir?: string): any; | ||
export type require = { | ||
cache: Map<string, {moduleExports: any, map: any}>, | ||
(path: string, currentWorkingDir?: string): any | ||
}; | ||
export function convert(code: JsxCode, options?: ConvertOptions): string|{code: string, map: null|object}; | ||
export type convert = { | ||
cache: Map<string, string>, | ||
(code: JsxCode, options?: ConvertOptions): string|{code: string, map: null|object}, | ||
}; | ||
@@ -38,0 +44,0 @@ export function run(code: JsxCode, options?: RunOptions): any; |
14
index.js
@@ -39,11 +39,11 @@ const React = require('react'); | ||
catch (err) { | ||
if (err && typeof err.stack === 'string') { | ||
Object.keys(requireJSX.cache).forEach(function (path) { | ||
var {map} = requireJSX.cache[path]; | ||
const stack = err && typeof err.stack === 'string' && err.stack; | ||
if (!map) return; | ||
if (stack) { | ||
for (const [path, {map}] of requireJSX.cache) { | ||
if (!map) continue; | ||
let pathJSX = path + '.jsx'; | ||
if (!err.stack.includes(pathJSX)) return; | ||
if (!stack.includes(pathJSX)) continue; | ||
@@ -53,3 +53,3 @@ const {SourceMapConsumer} = require('source-map-sync'); | ||
SourceMapConsumer.with(map, null, function (consumer) { | ||
err.stack = err.stack.replace(new RegExp(escapeRegexp(pathJSX) + ":(\\d+):(\\d+)", "g"), function (x, l, c) { | ||
err.stack = stack.replace(new RegExp(escapeRegexp(pathJSX) + ":(\\d+):(\\d+)", "g"), function (x, l, c) { | ||
let {line, column} = consumer.originalPositionFor({line: Number(l), column: Number(c)}); | ||
@@ -62,3 +62,3 @@ | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -65,0 +65,0 @@ |
{ | ||
"name": "express-engine-jsx", | ||
"version": "3.6.1", | ||
"version": "3.7.0", | ||
"description": "JSX engine for ExpressJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const {resolve, isAbsolute, dirname} = require('path'); | ||
const fs = require('fs'); | ||
const {existsSync, readFileSync} = require('fs'); | ||
const convert = require('./convert'); | ||
@@ -11,3 +11,3 @@ const run = require('./run'); | ||
requireJSX.cache = {}; | ||
requireJSX.cache = new Map(); | ||
@@ -20,3 +20,3 @@ function requireJSX(path, currentWorkingDir) { | ||
var resolvedPath = resolveJSX(path); | ||
const resolvedPath = resolveJSX(path); | ||
@@ -48,31 +48,31 @@ if (!resolvedPath) { | ||
let {cache} = requireJSX; | ||
const {cache} = requireJSX; | ||
if (cache[path]) return cache[path].moduleExports; | ||
if (cache.has(path)) return cache.get(path).moduleExports; | ||
if (fs.existsSync(path + '.js') || fs.existsSync(resolve(path, 'index.js'))) { | ||
if (existsSync(path + '.js') || existsSync(resolve(path, 'index.js'))) { | ||
return require(path); | ||
} | ||
var pathJSX; | ||
let pathJSX; | ||
if (!fs.existsSync((pathJSX = path + '.jsx')) && !fs.existsSync((pathJSX = resolve(path, 'index.jsx')))) { | ||
if (!existsSync((pathJSX = path + '.jsx')) && !existsSync((pathJSX = resolve(path, 'index.jsx')))) { | ||
throw new Error(`JSX file not found ${JSON.stringify(path)}`); | ||
} | ||
let result = convert(fs.readFileSync(pathJSX), { | ||
const result = convert(readFileSync(pathJSX), { | ||
path: pathJSX | ||
}); | ||
let code = typeof result === 'string' ? result : result.code; | ||
let map = typeof result === 'string' ? null : result.map; | ||
const code = typeof result === 'string' ? result : result.code; | ||
const map = typeof result === 'string' ? null : result.map; | ||
let moduleExports = run(code, { | ||
const moduleExports = run(code, { | ||
path: pathJSX | ||
}); | ||
cache[path] = { | ||
cache.set(path, { | ||
moduleExports, | ||
map, | ||
}; | ||
}); | ||
@@ -79,0 +79,0 @@ return moduleExports; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32979
456