Skip to content

Commit 7d642d9

Browse files
committed
refactor: a square is not a rectangle
1 parent 0ba8a54 commit 7d642d9

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

lib/sources/factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const glob = require('glob')
44

55
const _ = require('lodash')
66

7-
const Source = require('./source')
7+
const SimpleSource = require('./source')
88
const JsSource = require('./js-source')
99

1010
const FILE_PREFIX = 'file://'
@@ -68,7 +68,7 @@ class SourceFactory {
6868
return new JsSource(file.content)
6969
}
7070

71-
return new Source(file.content)
71+
return new SimpleSource(file.content)
7272
}
7373
}
7474

lib/sources/js-source.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const esprima = require('esprima')
22
const debug = require('debug')('nukecss:js-source')
3-
const Source = require('./source')
3+
const SimpleSource = require('./source')
44

5-
class JsSource extends Source {
5+
class JsSource {
66
constructor(text, opts = {}) {
7-
super(text)
7+
this._text = text
88

99
let tokens = opts.tokens
1010
if (!tokens) {
@@ -28,7 +28,7 @@ class JsSource extends Source {
2828
}
2929

3030
_findWholeSelectorInTokens(selector) {
31-
return this._tokensArray.find(token => Source.textContains(token, selector))
31+
return this._tokensArray.find(token => SimpleSource.textContains(token, selector))
3232
}
3333

3434
_findSelectorPartsInTokens(selector) {
@@ -53,7 +53,7 @@ class JsSource extends Source {
5353
this._findWholeSelectorInTokens(selector) ||
5454
this._findSelectorPartsInTokens(selector))
5555
} else {
56-
return Source.textContains(this._text, selector)
56+
return SimpleSource.textContains(this._text, selector)
5757
}
5858
}
5959

lib/sources/source.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Source {
1+
class SimpleSource {
22
constructor(text) {
33
this._text = text
44
}
@@ -8,20 +8,20 @@ class Source {
88
}
99

1010
contains(selector) {
11-
return Source.textContains(this._text, selector)
11+
return SimpleSource.textContains(this._text, selector)
1212
}
1313

1414
join(source) {
1515
if (source.type !== 'simple') {
16-
throw new Error('Source can only be joined with Source')
16+
throw new Error('SimpleSource can only be joined with SimpleSource')
1717
}
1818

19-
return new Source(`${this._text} ${source._text}`)
19+
return new SimpleSource(`${this._text} ${source._text}`)
2020
}
2121

2222
static textContains(text, selector) {
2323
return new RegExp(`\\b${selector}\\b`, 'i').test(text)
2424
}
2525
}
2626

27-
module.exports = Source
27+
module.exports = SimpleSource

test/sources/factory.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('sources/factory.js', () => {
9393

9494
context('when opts.simple=true', () => {
9595
const opts = {simple: true}
96-
it('should always use Source', () => {
96+
it('should always use SimpleSource', () => {
9797
const content = 'const foobar = "baz"'
9898
const sources = SourceFactory.fromObject({content, type: 'js'}, opts)
9999
expect(sources).to.have.length(1)

0 commit comments

Comments
 (0)