Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various updates #2

Merged
merged 13 commits into from
Sep 5, 2017
Merged
Prev Previous commit
Next Next commit
Make parser properly parse top-level component comments, even when th…
…e component is not preceded with a top-level variable declaration.
  • Loading branch information
magali-br committed Jun 15, 2017
commit 8e19b53f89f16ab6747463df10855430d8384102
8 changes: 4 additions & 4 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ class Parser extends EventEmitter {
walk () {
process.nextTick(() => {
this.ast.body.forEach((body) => {
if (body.type !== 'ExportDefaultDeclaration' && body.type !== 'ExpressionStatement') {
const entry = getComment(body)
const description = entry ? entry.description : null
const entry = getComment(body)
Copy link
Member

Choose a reason for hiding this comment

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

Great @magali-br. This commit fixes the #1 issue
👍

const description = entry ? entry.description : null
this.emit('description', description)

this.emit('description', description)
if (body.type !== 'ExportDefaultDeclaration' && body.type !== 'ExpressionStatement') {
return
}

Expand Down
138 changes: 138 additions & 0 deletions test/fixtures/checkboxNoTopLevelConstant.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<template>
<label>
<input :disabled="disabled" type="text" v-model="checkbox">
<!-- Default slot -->
<slot></slot>
<!-- Use this slot to set the checkbox label -->
<slot name="label">Unamed checkbox</slot>
<!--
This
is multiline description
-->
<slot name="multiline">Unamed checkbox</slot>
<slot name="undescribed"></slot>
<template></template>
</label>
</template>

<script>

/**
* A simple checkbox component
*/
export default {
name: 'checkbox',
props: {
/**
* The checkbox model
* @model
*/
model: {
type: Array,
required: true,
twoWay: true
},

/**
* Initial checkbox state
*/
disabled: Boolean,

/**
* Initial checkbox value
*/
checked: {
type: Boolean,
default: true
},

// Prop with camel name
propWithCamel: {
type: Object,
default: () => ({ name: 'X'})
}
},

data () {
return {}
},

created () {
/**
* Emit when the component has been loaded
*/
this.$emit('loaded')
},

methods: {
/**
* @private
*/
privateMethod () {
console.log('check')

const name = 'check'
const value = 'event value'

if (name) {
console.log('>', name)
}

/**
* Event with identifier name
*/
this.$emit(name, value)
},

/**
* Check the checkbox
*/
check () {
console.log('check')

let eventName = 'check'
const value = 'event value'

if (eventName) {
console.log('>', eventName)
}

eventName = 'renamed'

/**
* Event with renamed identifier name
*/
this.$emit(eventName, value)
},

/**
* @protected
*/
recursiveIdentifierValue () {
console.log('check')

let recursiveValue = 'recursive'
const value = 'event value'

if (eventName) {
console.log('>', eventName)
}

eventName = recursiveValue

/**
* Event with recursive identifier name
*/
this.$emit(eventName, value)
},

uncommentedMethod () {}
}
}
</script>

<style lang="css" scoped>
label {
font-size: .9em
}
</style>
8 changes: 8 additions & 0 deletions test/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const optionsForModuleExports = {
ignoredVisibilities: []
}

const optionsNoTopLevelConstant = {
filename: f('checkboxNoTopLevelConstant.vue'),
encoding: 'utf8',
ignoredVisibilities: []
}

const optionsWithFileSource = {
filecontent: fs.readFileSync(f('checkbox.vue'), 'utf8'),
ignoredVisibilities: []
Expand Down Expand Up @@ -60,6 +66,8 @@ describe('component', () => testComponent(options))

describe('component_module.exports', () => testComponent(optionsForModuleExports))

describe('component_no-top-level-constant', () => testComponent(optionsNoTopLevelConstant))

describe('component_filesource', () => testComponent(optionsWithFileSource))

function testComponent(optionsToParse) {
Expand Down