Skip to content

Commit

Permalink
ts
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Dec 7, 2019
1 parent 2f80d5a commit 122f2a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions build/build-cdt-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ execFileSync('node_modules/.bin/tsc', [
console.log('making modifications ...');

for (const file of glob.sync(`${outDir}/**/*.js`)) {
const code = fs.readFileSync(file, 'utf-8')
.replace('exports["default"]', 'exports.default');
const code = fs.readFileSync(file, 'utf-8');

let lines = code.match(/^.*(\r?\n|$)/mg) || [];
const cutoffIndex = lines.findIndex(line => line.includes('Legacy exported object'));
Expand All @@ -43,6 +42,8 @@ for (const file of glob.sync(`${outDir}/**/*.js`)) {
if (file.endsWith('ParsedURL.js')) {
newLine = newLine.replace(/Common.ParsedURL/g, 'ParsedURL');
}
newLine = newLine.replace('exports["default"]', 'exports.default');

if (newLine !== line) {
// eslint-disable-next-line no-console
console.log(`${file}:${i}: ${line.trim()}`);
Expand Down
7 changes: 6 additions & 1 deletion lighthouse-core/lib/cdt/SDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';
// @ts-nocheck

const SDK = {
...require('./generated/sdk/SourceMap.js'),
Expand All @@ -18,6 +17,9 @@ SDK.TextSourceMap.prototype.mappings = function() {
};

/**
* Copied from CDT utilities.js. This is the only method needed from
* that file.
*
* Return index of the leftmost element that is greater
* than the specimen object. If there's no such element (i.e. all
* elements are smaller or equal to the specimen) returns right bound.
Expand All @@ -34,6 +36,7 @@ SDK.TextSourceMap.prototype.mappings = function() {
* @template T,S
*/
function upperBound(object, comparator, left, right) {
// @ts-ignore
function defaultComparator(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
Expand Down Expand Up @@ -74,12 +77,14 @@ SDK.TextSourceMap.prototype.findExactEntry = function(line, column) {
// Add `lastColumnNumber` to mappings.
SDK.TextSourceMap.prototype.computeLastGeneratedColumns = function() {
const mappings = this.mappings();
// @ts-ignore: `lastColumnNumber` is not on types yet.
if (mappings.length && typeof mappings[0].lastColumnNumber !== 'undefined') return;

for (let i = 0; i < mappings.length - 1; i++) {
const mapping = mappings[i];
const nextMapping = mappings[i + 1];
if (mapping.lineNumber === nextMapping.lineNumber) {
// @ts-ignore: `lastColumnNumber` is not on types yet.
mapping.lastColumnNumber = nextMapping.columnNumber;
}
}
Expand Down

0 comments on commit 122f2a2

Please sign in to comment.