Skip to content

Conversation

@Zerogiven
Copy link

With this pull request we can handle "extends" at tsconfig. Multiple extends are possible too. The only thing to note is that a small part of readFile is not async cause we have to await some results.

I also removed the filename parameter from the parse method cause it was never used.

At least i've added a test with some mockups for extending tsconfig.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 96.316% when pulling 28fa0da on Zerogiven:patch-1 into 5281eaf on TypeStrong:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 96.316% when pulling 28fa0da on Zerogiven:patch-1 into 5281eaf on TypeStrong:master.

…xtending. This is needed cause code coverage is collected from the compiled JS files and not from the TS ones.
@Zerogiven Zerogiven changed the title Patch 1 Handle "extends" Jan 6, 2018

if (obj.extends !== undefined) {
const filepath = filename.replace(path.basename(filename), '')
const extendsFilename = resolveSync(filepath, obj.extends) as string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't do a synchronous operation in an async context, it defeats the purpose of supporting an async API.

return reject(err)
}

let obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for let here, mergeObjects is mutating target anyway.


let obj
try {
return resolve(parse(contents, filename))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd need to keep the signature backward compatible here, otherwise it's a breaking change. I'd just make it optional, it used to be used for debugging and would still be useful to figure out which file has the syntax error.

* Simple object merging
*/
function mergeObjects (target: any, source: any): any {
for (let key of Object.keys(source)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const key

*/
function mergeObjects (target: any, source: any): any {
for (let key of Object.keys(source)) {
if (source[key] instanceof Object) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make a little isObject helper over using instanceof personally.

function mergeObjects (target: any, source: any): any {
for (let key of Object.keys(source)) {
if (source[key] instanceof Object) {
Object.assign(source[key], mergeObjects(target[key], source[key]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of confusing, you're assigning backward onto the source and then copying back onto the target in a roundabout way - you could just use an else statement and make both assign to target and delete the final Object.assign to avoid additional work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants