Skip to content

Commit

Permalink
Track firstReturnOutsideFunction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 28, 2019
1 parent 24c8bdc commit 353fb1e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ if (cachePath !== "") {
codeWithTDZ: null,
filename: null,
firstAwaitOutsideFunction: null,
firstReturnOutsideFunction: null,
mtime: -1,
scriptData,
sourceType: 1,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esm",
"version": "3.2.21",
"version": "3.2.22-pre",
"description": "Tomorrow's ECMAScript modules today!",
"keywords": "commonjs, ecmascript, export, import, modules, node, require",
"repository": "standard-things/esm",
Expand Down
42 changes: 28 additions & 14 deletions src/caching-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function init() {
codeWithTDZ: null,
filename: null,
firstAwaitOutsideFunction: null,
firstReturnOutsideFunction: null,
mtime: -1,
scriptData: null,
sourceType: SOURCE_TYPE_SCRIPT,
Expand All @@ -75,7 +76,7 @@ function init() {
}

if (length > 2) {
const filename = meta[6]
const filename = meta[7]

if (typeof filename === "string") {
result.filename = resolve(pkg.cachePath, filename)
Expand All @@ -84,10 +85,13 @@ function init() {
const deflatedFirstAwaitOutsideFunction = meta[5]

if (deflatedFirstAwaitOutsideFunction !== null) {
result.firstAwaitOutsideFunction = {
column: deflatedFirstAwaitOutsideFunction[0],
line: deflatedFirstAwaitOutsideFunction[1]
}
result.firstAwaitOutsideFunction = inflateLineInfo(deflatedFirstAwaitOutsideFunction)
}

const deflatedFirstReturnOutsideFunction = meta[6]

if (deflatedFirstReturnOutsideFunction !== null) {
result.firstReturnOutsideFunction = inflateLineInfo(deflatedFirstReturnOutsideFunction)
}

result.mtime = +meta[3]
Expand All @@ -98,8 +102,8 @@ function init() {
if (length > 7 &&
result.sourceType === SOURCE_TYPE_MODULE) {
entry.type = TYPE_ESM
result.circular = +meta[7]
result.yieldIndex = +meta[8]
result.circular = +meta[8]
result.yieldIndex = +meta[9]
}

const [offsetStart, offsetEnd] = meta
Expand Down Expand Up @@ -153,6 +157,14 @@ function init() {
return result
}

function deflateLineInfo({ column, line }) {
return [column, line]
}

function inflateLineInfo([column, line]) {
return { column, line }
}

function onExit() {
setMaxListeners(Math.max(getMaxListeners() - 1, 0))

Expand Down Expand Up @@ -295,19 +307,19 @@ function init() {
const {
filename,
firstAwaitOutsideFunction,
firstReturnOutsideFunction,
mtime,
sourceType,
transforms
} = compileData

let deflatedFirstAwaitOutsideFunction = null
const deflatedFirstAwaitOutsideFunction = firstAwaitOutsideFunction === null
? null
: deflateLineInfo(firstAwaitOutsideFunction)

if (firstAwaitOutsideFunction !== null) {
deflatedFirstAwaitOutsideFunction = [
firstAwaitOutsideFunction.column,
firstAwaitOutsideFunction.line
]
}
const deflatedFirstReturnOutsideFunction = firstReturnOutsideFunction === null
? null
: deflateLineInfo(firstReturnOutsideFunction)

if (sourceType === SOURCE_TYPE_SCRIPT) {
if (transforms !== 0) {
Expand All @@ -316,6 +328,7 @@ function init() {
mtime,
sourceType,
deflatedFirstAwaitOutsideFunction,
deflatedFirstReturnOutsideFunction,
relative(cachePath, filename)
)
}
Expand All @@ -325,6 +338,7 @@ function init() {
mtime,
sourceType,
deflatedFirstAwaitOutsideFunction,
deflatedFirstReturnOutsideFunction,
relative(cachePath, filename),
compileData.circular,
compileData.yieldIndex
Expand Down
2 changes: 2 additions & 0 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function init() {
codeWithTDZ: null,
filename: null,
firstAwaitOutsideFunction: null,
firstReturnOutsideFunction: null,
mtime: -1,
scriptData: null,
sourceType: SOURCE_TYPE_SCRIPT,
Expand Down Expand Up @@ -342,6 +343,7 @@ function init() {
}

result.firstAwaitOutsideFunction = top.firstAwaitOutsideFunction
result.firstReturnOutsideFunction = top.firstReturnOutsideFunction
result.sourceType = sourceType
result.yieldIndex = yieldIndex

Expand Down
1 change: 1 addition & 0 deletions src/module/internal/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function compile(caller, entry, content, filename, fallback) {
codeWithTDZ: null,
filename: null,
firstAwaitOutsideFunction: null,
firstReturnOutsideFunction: null,
mtime: -1,
scriptData: null,
sourceType: hint,
Expand Down

0 comments on commit 353fb1e

Please sign in to comment.