From 9bdb95c9e34cef640534e5e5a1e2225a80442000 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期四, 09 六月 2022 15:48:15 +0800
Subject: [PATCH] TODO#139894 [ footer -最下方說明與保經代合作 ] 文案修改

---
 PAMapp/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js |   45 +++++++++++++++++++++++++++++++++------------
 1 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/PAMapp/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js b/PAMapp/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js
index 2a8dc40..1b56af1 100644
--- a/PAMapp/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js
+++ b/PAMapp/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js
@@ -1,10 +1,13 @@
 const assert = require('assert')
 const convertSourceMap = require('convert-source-map')
+const util = require('util')
+const debuglog = util.debuglog('c8')
 const { dirname, isAbsolute, join, resolve } = require('path')
 const { fileURLToPath } = require('url')
 const CovBranch = require('./branch')
 const CovFunction = require('./function')
 const CovSource = require('./source')
+const { sliceRange } = require('./range')
 const compatError = Error(`requires Node.js ${require('../package.json').engines.node}`)
 let readFile = () => { throw compatError }
 try {
@@ -51,6 +54,9 @@
     if (this.rawSourceMap) {
       if (this.rawSourceMap.sourcemap.sources.length > 1) {
         this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap)
+        if (!this.sourceMap.sourcesContent) {
+          this.sourceMap.sourcesContent = await this.sourcesContentFromSources()
+        }
         this.covSources = this.sourceMap.sourcesContent.map((rawSource, i) => ({ source: new CovSource(rawSource, this.wrapperLength), path: this.sourceMap.sources[i] }))
         this.sourceTranspiled = new CovSource(rawSource, this.wrapperLength)
       } else {
@@ -83,6 +89,18 @@
     }
   }
 
+  async sourcesContentFromSources () {
+    const fileList = this.sourceMap.sources.map(relativePath => {
+      const realPath = this._resolveSource(this.rawSourceMap, relativePath)
+      return readFile(realPath, 'utf-8')
+        .then(result => result)
+        .catch(err => {
+          debuglog(`failed to load ${realPath}: ${err.message}`)
+        })
+    })
+    return await Promise.all(fileList)
+  }
+
   destroy () {
     if (this.sourceMap) {
       this.sourceMap.destroy()
@@ -112,22 +130,25 @@
         if (this.excludePath(path)) {
           return
         }
-        const lines = covSource.lines.filter(line => {
-          // Upstream tooling can provide a block with the functionName
-          // (empty-report), this will result in a report that has all
-          // lines zeroed out.
-          if (block.functionName === '(empty-report)') {
+        let lines
+        if (block.functionName === '(empty-report)') {
+          // (empty-report), this will result in a report that has all lines zeroed out.
+          lines = covSource.lines.filter((line) => {
             line.count = 0
-            this.all = true
             return true
-          }
+          })
+          this.all = lines.length > 0
+        } else {
+          lines = sliceRange(covSource.lines, startCol, endCol)
+        }
+        if (!lines.length) {
+          return
+        }
 
-          return startCol < line.endCol && endCol >= line.startCol
-        })
         const startLineInstance = lines[0]
         const endLineInstance = lines[lines.length - 1]
 
-        if (block.isBlockCoverage && lines.length) {
+        if (block.isBlockCoverage) {
           this.branches[path] = this.branches[path] || []
           // record branches.
           this.branches[path].push(new CovBranch(
@@ -138,7 +159,7 @@
             range.count
           ))
 
-          // if block-level granularity is enabled, we we still create a single
+          // if block-level granularity is enabled, we still create a single
           // CovFunction tracking object for each set of ranges.
           if (block.functionName && i === 0) {
             this.functions[path] = this.functions[path] || []
@@ -151,7 +172,7 @@
               range.count
             ))
           }
-        } else if (block.functionName && lines.length) {
+        } else if (block.functionName) {
           this.functions[path] = this.functions[path] || []
           // record functions.
           this.functions[path].push(new CovFunction(

--
Gitblit v1.8.0